CF542B.Duck Hunt
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A duck hunter is doing his favorite thing, hunting. He lives in a two dimensional world and is located at point (0, 0). As he doesn't like walking for his prey, he prefers to shoot only vertically up (because in this case, the ducks fall straight into his hands). The hunter doesn't reload the gun immediately — r or more seconds must pass between the shots. When the hunter shoots up, the bullet immediately hits all the ducks who are directly above the hunter.
In a two dimensional world each duck is a horizontal segment that moves horizontally in the negative direction of the Ox axis at the speed 1 length unit per second. For each duck we know the values h__i and t__i — the x-coordinates of its head (the left end of the segment) and its tail (the right end of the segment) at time 0. The height where the duck is flying isn't important as the gun shoots vertically up to the infinite height and hits all the ducks on its way.
The figure to the first sample.
What maximum number of ducks can the hunter shoot? The duck is considered shot by the hunter if at the moment of the shot at least one of its point intersects the Oy axis. After the hunter shoots the duck, it falls and it can't be shot anymore. The hunter cannot make shots before the moment of time 0.
一名鸭子猎人正在做他最喜欢的事情——狩猎。他生活在一个二维世界中,且位于点 (0, 0) 处。由于他不喜欢为猎物而步行,他只愿意垂直向上射击(因为此时鸭子会直接垂直落入他的手中)。猎人不会立即为枪重新装弹——两次射击之间必须间隔至少 r 秒。当猎人垂直向上射击时,子弹会瞬间击中所有正位于他正上方的鸭子。
在这个二维世界中,每只鸭子是一条水平线段,以每秒 1 个长度单位的速度沿 Ox 轴负方向水平移动。对于每只鸭子 i,我们已知其在时刻 0 时头部(线段左端点)和尾部(线段右端点)的 x 坐标分别为 hi 和 ti。鸭子飞行的高度并不重要,因为枪是垂直向上无限射出的,路径上所有鸭子均会被击中。
第一个样例对应的示意图。
猎人最多能击中多少只鸭子?若在某次射击发生的时刻,鸭子的至少一个点与 Oy 轴相交,则该鸭子被视为被猎人击中。猎人击中鸭子后,该鸭子即坠落,无法再被击中。猎人不能在时刻 0 之前开枪。
输入格式
The first line of the input contains integers n, r (1 ≤ n ≤ 200 000, 1 ≤ r ≤ 109) — the number of ducks and the minimum time in seconds between the shots.
Then n lines follow, each of them contains two integers h__i, t__i ( - 109 ≤ h__i < t__i ≤ 109) — the x-coordinate of the head and tail of the i-th duck at the moment 0.
输入的第一行包含两个整数 n、r(1 ≤ n ≤ 200000,1 ≤ r ≤ 109)——分别表示鸭子的数量以及两次射击之间所需的最短时间(单位:秒)。
接下来有 n 行,每行包含两个整数 hi、ti(−109 ≤ hi < ti ≤ 109)——表示第 i 只鸭子在时刻 0 时其头部与尾部的 x 坐标。
输出格式
Print a single integer — the maximum number of ducks that can be shot by the hunter.
输出一个整数——猎人能够射杀的鸭子的最大数量。
输入输出样例
输入#1
3 3 -3 0 1 3 -1 2
输出#1
3
输入#2
4 5 -1 1 2 4 5 9 6 8
输出#2
3
说明/提示
In the first sample the hunter must shoot at time 0, this shot kills ducks 1 and 3. Then the hunter needs to reload the gun and shoot again at time 3. His second shot hits the tail of duck 2.
In the second sample the hunter can make shots at times 0 and 6 to hit three ducks.
在第一个样例中,猎人必须在时刻 0 射击,这一枪击中了鸭子 1 和鸭子 3。随后猎人需要为枪支重新装弹,并在时刻 3 再次射击。他的第二枪击中了鸭子 2 的尾部。
在第二个样例中,猎人可以在时刻 0 和时刻 6 射击,从而击中三只鸭子。
输入解题思路,AI测评打分。不知道怎么写?