CF1041D.Glider
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A plane is flying at a constant height of h meters above the ground surface. Let's consider that it is flying from the point (−109,h) to the point (109,h) parallel with Ox axis.
A glider is inside the plane, ready to start his flight at any moment (for the sake of simplicity let's consider that he may start only when the plane's coordinates are integers). After jumping from the plane, he will fly in the same direction as the plane, parallel to Ox axis, covering a unit of distance every second. Naturally, he will also descend; thus his second coordinate will decrease by one unit every second.
There are ascending air flows on certain segments, each such segment is characterized by two numbers x1 and x2 (x1<x2) representing its endpoints. No two segments share any common points. When the glider is inside one of such segments, he doesn't descend, so his second coordinate stays the same each second. The glider still flies along Ox axis, covering one unit of distance every second.
If the glider jumps out at 1, he will stop at 10. Otherwise, if he jumps out at 2, he will stop at 12.
Determine the maximum distance along Ox axis from the point where the glider's flight starts to the point where his flight ends if the glider can choose any integer coordinate to jump from the plane and start his flight. After touching the ground the glider stops altogether, so he cannot glide through an ascending airflow segment if his second coordinate is 0.
一架飞机在地面上方恒定高度 h 米处飞行。我们假设它沿 Ox 轴方向,从点 (−109,h) 飞行至点 (109,h)。
一名滑翔者位于飞机内,可在任意时刻跳出飞机开始滑翔(为简化问题,我们仅考虑他在飞机坐标为整数时跳出)。跳出后,他将沿与飞机相同的方向、即平行于 Ox 轴的方向飞行,每秒前进一个单位距离。自然地,他也会下降;因此其纵坐标(即第二坐标)每秒减少一个单位。
某些线段上存在上升气流,每个这样的线段由两个数 x1 和 x2(满足 x1<x2)表示其端点。任意两个上升气流线段之间无公共点。当滑翔者处于任一上升气流线段内部时,他不会下降,即其纵坐标每秒保持不变。滑翔者仍沿 Ox 轴方向飞行,每秒前进一个单位距离。
若滑翔者在位置 1 跳出,则他将在位置 10 处落地停止;若在位置 2 跳出,则他将在位置 12 处落地停止。
请确定:若滑翔者可自由选择任意整数横坐标位置跳出飞机并开始滑翔,则其滑翔轨迹沿 Ox 轴方向的起点到终点之间的最大距离是多少?滑翔者一旦触地(即纵坐标变为 0)便立即完全停止,因此他无法在纵坐标为 0 时穿越任何上升气流线段。
输入格式
The first line contains two integers n and h (1≤n≤2⋅105,1≤h≤109) — the number of ascending air flow segments and the altitude at which the plane is flying, respectively.
Each of the next n lines contains two integers xi1 and xi2 (1≤xi1<xi2≤109) — the endpoints of the i-th ascending air flow segment. No two segments intersect, and they are given in ascending order.
第一行包含两个整数 n 和 h(1≤n≤2⋅105,1≤h≤109),分别表示上升气流段的数量和飞机的飞行高度。
接下来的 n 行中,每行包含两个整数 xi1 和 xi2(1≤xi1<xi2≤109),表示第 i 个上升气流段的两个端点。任意两个气流段互不相交,且这些气流段按升序给出。
输出格式
Print one integer — the maximum distance along Ox axis that the glider can fly from the point where he jumps off the plane to the point where he lands if he can start his flight at any integer coordinate.
输出一个整数——滑翔者从飞机上跳下到落地点沿 Ox 轴方向所能飞行的最大距离(他可以从任意整数坐标处开始飞行)。
输入输出样例
输入#1
3 4 2 5 7 9 10 11
输出#1
10
输入#2
5 10 5 7 11 12 16 20 25 26 30 33
输出#2
18
输入#3
1 1000000000 1 1000000000
输出#3
1999999999
说明/提示
In the first example if the glider can jump out at (2,4), then the landing point is (12,0), so the distance is 12−2=10.
In the second example the glider can fly from (16,10) to (34,0), and the distance is 34−16=18.
In the third example the glider can fly from (−100,1000000000) to (1999999899,0), so the distance is 1999999899−(−100)=1999999999.
在第一个例子中,如果滑翔机可以在 (2,4) 处跳出,则落地点为 (12,0),因此距离为 12−2=10。
在第二个例子中,滑翔机可以从 (16,10) 飞行至 (34,0),距离为 34−16=18。
在第三个例子中,滑翔机可以从 (−100,1000000000) 飞行至 (1999999899,0),因此距离为 1999999899−(−100)=1999999999。
输入解题思路,AI测评打分。不知道怎么写?