CF883A Automatic Door
题目描述
工厂里有一个自动门:
- 如果门关着,并来了一个或多个人,门立即打开,所有人立刻进去。
- 如果门开着,并来了一个或多个人,所有人立即进去。
- 门打开后$d$ 秒立刻关上。
- 门在关的瞬间,如果来了一个或多个人,这些人立刻进去,之后门关上。
例如,$d=3$ 时,有四个人分别在以下时刻到来:$\{4,7,9,13\}$ ,
那么门会开三次:$\{4,9,13\}$ ,
门会在以下时刻关闭:$\{7,12\}$ 。
你提前知道了公司有一批员工分别在$a,2a,3a,\cdots ,na(a\in \mathbf{Z^+})$ 时刻到来。另外有$m$ 位顾客分别在$t_{1},t_{2},\cdots,t_{m}$ 时刻到来。
最初门是关闭的。
试问门会开几次。
输入格式
第一行$n,m,a,d(1\le n,a\le 10^{9},1\le m\le 10^{5},1\le d\le 10^{18})$ ,分别代表有$n$ 个员工,$m$ 个顾客,第一个员工来的时间$a$ ,和,门开的持续时间$d$ 。
第二行$m$ 个数$t_{1},t_{2},...,t_{m}(1\le t_{i}\le 10^{18})$ ,表示顾客来的时间。保证为升序排列。
输出格式
输出门开的次数
翻译贡献者UID:50882
说明/提示
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.