CF1907D.Jumping Through Segments

普及/提高-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp is designing a level for a game. The level consists of nn segments on the number line, where the ii-th segment starts at the point with coordinate lil_i and ends at the point with coordinate rir_i.

The player starts the level at the point with coordinate 00. In one move, they can move to any point that is within a distance of no more than kk. After their ii-th move, the player must land within the ii-th segment, that is, at a coordinate xx such that li≤x≤ril_i \le x \le r_i. This means:

  • After the first move, they must be inside the first segment (from l1l_1 to r1r_1);
  • After the second move, they must be inside the second segment (from l2l_2 to r2r_2);
  • ...
  • After the nn-th move, they must be inside the nn-th segment (from lnl_n to rnr_n).

The level is considered completed if the player reaches the nn-th segment, following the rules described above. After some thought, Polycarp realized that it is impossible to complete the level with some values of kk.

Polycarp does not want the level to be too easy, so he asks you to determine the minimum integer kk with which it is possible to complete the level.

Polycarp 正在为一款游戏设计一个关卡。该关卡由数轴上的 nn 个线段组成,其中第 ii 个线段起始于坐标 lil_i,终止于坐标 rir_i。

玩家从坐标为 00 的点开始闯关。每次移动中,玩家最多可移动距离 kk(即:移动后与移动前的坐标之差的绝对值不超过 kk)。在第 ii 次移动之后,玩家必须落在第 ii 个线段内,即其坐标 xx 需满足 li≤x≤ril_i \le x \le r_i。这意味着:

  • 第一次移动后,玩家必须位于第一个线段内(即坐标在 l1l_1 到 r1r_1 之间);
  • 第二次移动后,玩家必须位于第二个线段内(即坐标在 l2l_2 到 r2r_2 之间);
  • …
  • 第 nn 次移动后,玩家必须位于第 nn 个线段内(即坐标在 lnl_n 到 rnr_n 之间)。

若玩家能按上述规则到达第 nn 个线段,则该关卡视为完成。经过思考,Polycarp 意识到:对某些 kk 值,该关卡根本无法完成。

Polycarp 不希望关卡过于简单,因此他请你找出能够完成该关卡的最小整数 kk。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4)—the number of test cases. Descriptions of the test cases follow.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—the number of segments in the level.

The following nn lines.

The ii-th line contain two integers lil_i and rir_i (0≤li≤ri≤1090 \le l_i \le r_i \le 10^9)—the boundaries of the ii-th segment. Segments may intersect.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——关卡中线段的数量。

接下来 nn 行。

第 ii 行包含两个整数 lil_i 和 rir_i(0≤li≤ri≤1090 \le l_i \le r_i \le 10^9)——第 ii 条线段的边界。线段之间可以相交。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer—the minimum value of kk with which it is possible to complete the level.

对于每个测试用例,输出一个整数——能够完成该关卡的最小 kk 值。

输入输出样例

  • 输入#1

    4
    5
    1 5
    3 4
    5 6
    8 10
    0 1
    3
    0 2
    0 1
    0 3
    3
    3 8
    10 18
    6 11
    4
    10 20
    0 5
    15 17
    2 2

    输出#1

    7
    0
    5
    13

说明/提示

In the third example, the player can make the following moves:

  • Move from point 00 to point 55 (3≤5≤83 \le 5 \le 8);
  • Move from point 55 to point 1010 (10≤10≤1810 \le 10 \le 18);
  • Move from point 1010 to point 77 (6≤7≤116 \le 7 \le 11).

Note that for the last move, the player could have chosen not to move and still complete the level.

在第三个例子中,玩家可以执行以下操作:

  • 从点 00 移动到点 55(满足 3≤5≤83 \le 5 \le 8);
  • 从点 55 移动到点 1010(满足 10≤10≤1810 \le 10 \le 18);
  • 从点 1010 移动到点 77(满足 6≤7≤116 \le 7 \le 11)。

注意:对于最后一次移动,玩家本可以选择不移动,依然能完成关卡。

输入解题思路,AI测评打分。不知道怎么写?

首页