A11457 | Automatic Door
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is an automatic door at the entrance of a factory. The door works in the following way:
- when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside,
- when one or several people come to the door and it is open, all people immediately come inside,
- opened door immediately closes in $d$ seconds after its opening,
- if the door is closing and one or several people are coming to the door at the same moment, then all of them will have enough time to enter and only after that the door will close.
For example, if $d=3$ and four people are coming at four different moments of time $t_{1}=4$ , $t_{2}=7$ , $t_{3}=9$ and $t_{4}=13$ then the door will open three times: at moments $4$ , $9$ and $13$ . It will close at moments $7$ and $12$ .
It is known that $n$ employees will enter at moments $a,2·a,3·a,...,n·a$ (the value $a$ is positive integer). Also $m$ clients will enter at moments $t_{1},t_{2},...,t_{m}$ .
Write program to find the number of times the automatic door will open. Assume that the door is initially closed.
- when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside,
- when one or several people come to the door and it is open, all people immediately come inside,
- opened door immediately closes in $d$ seconds after its opening,
- if the door is closing and one or several people are coming to the door at the same moment, then all of them will have enough time to enter and only after that the door will close.
For example, if $d=3$ and four people are coming at four different moments of time $t_{1}=4$ , $t_{2}=7$ , $t_{3}=9$ and $t_{4}=13$ then the door will open three times: at moments $4$ , $9$ and $13$ . It will close at moments $7$ and $12$ .
It is known that $n$ employees will enter at moments $a,2·a,3·a,...,n·a$ (the value $a$ is positive integer). Also $m$ clients will enter at moments $t_{1},t_{2},...,t_{m}$ .
Write program to find the number of times the automatic door will open. Assume that the door is initially closed.
输入格式
The first line contains four integers $n$ , $m$ , $a$ and $d$ ( $1<=n,a<=10^{9}$ , $1<=m<=10^{5}$ , $1<=d<=10^{18}$ ) — the number of the employees, the number of the clients, the moment of time when the first employee will come and the period of time in which the door closes.
The second line contains integer sequence $t_{1},t_{2},...,t_{m}$ ( $1<=t_{i}<=10^{18}$ ) — moments of time when clients will come. The values $t_{i}$ are given in non-decreasing order.
The second line contains integer sequence $t_{1},t_{2},...,t_{m}$ ( $1<=t_{i}<=10^{18}$ ) — moments of time when clients will come. The values $t_{i}$ are given in non-decreasing order.
输出格式
Print the number of times the door will open.
输入输出样例
输入 #1
1 1 3 4 7
输出 #1
1
输入 #2
4 3 4 2 7 9 11
输出 #2
4
In the first example the only employee will come at moment $3$ . At this moment the door will open and will stay open until the moment $7$ . At the same moment of time the client will come, so at first he will enter and only after it the door will close. Thus the door will open one time.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted