CF883A.Automatic Door
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
工厂入口处有一扇自动门。该门的工作方式如下:
- 当一个或多个人员到达门口且门处于关闭状态时,门立即自动打开,所有人员立即进入;
- 当一个或多个人员到达门口且门处于开启状态时,所有人员立即进入;
- 门在开启后 d 秒立即关闭;
- 若门正在关闭过程中,恰好有一个人或多人在同一时刻到达门口,则他们均有足够时间进入,之后门才关闭。
例如,若 d = 3,且四个人分别在四个不同时间点 _t_₁ = 4、_t_₂ = 7、_t_₃ = 9 和 _t_₄ = 13 到达,则门将共开启三次:分别在时刻 4、9 和 13;并将在时刻 7 和 12 关闭。
已知有 n 名员工将在时刻 a, 2·a, 3·a, ..., n·a 进入(其中 a 为正整数);另有 m 名客户将在时刻 _t_₁, _t_₂, ..., t__m 进入。
请编写程序,计算自动门总共开启的次数。假设初始状态下门是关闭的。
输入格式
The first line contains four integers n, m, a and d (1 ≤ n, a ≤ 109, 1 ≤ m ≤ 105, 1 ≤ d ≤ 1018) — 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 ≤ 1018) — moments of time when clients will come. The values t__i are given in non-decreasing order.
第一行包含四个整数 n、m、a 和 d(1 ≤ n, a ≤ 109,1 ≤ m ≤ 105,1 ≤ d ≤ 1018)—— 分别表示员工人数、客户人数、第一位员工到达的时刻,以及门关闭的时间周期。
第二行包含一个整数序列 t1, t2, ..., tm(1 ≤ ti ≤ 1018)—— 表示客户到达的时刻。这些值 ti 按非递减顺序给出。
输出格式
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.
在第一个例子中,唯一的员工将在时刻 3 到达。此时门将开启,并保持开启状态直至时刻 7。在同一时刻,客户也将到达,因此客户将首先进入,之后门才会关闭。因此,门总共开启一次。
输入解题思路,AI测评打分。不知道怎么写?