CF1872B.The Corridor or There and Back Again

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are in a corridor that extends infinitely to the right, divided into square rooms. You start in room 11, proceed to room kk, and then return to room 11. You can choose the value of kk. Moving to an adjacent room takes 11 second.

Additionally, there are nn traps in the corridor: the ii-th trap is located in room did_i and will be activated sis_i seconds after you enter the room di\boldsymbol{d_i}. Once a trap is activated, you cannot enter or exit a room with that trap.

A schematic representation of a possible corridor and your path to room kk and back.

Determine the maximum value of kk that allows you to travel from room 11 to room kk and then return to room 11 safely.

For instance, if n=1n=1 and d1=2,s1=2d_1=2, s_1=2, you can proceed to room k=2k=2 and return safely (the trap will activate at the moment 1+s1=1+2=31+s_1=1+2=3, it can't prevent you to return back). But if you attempt to reach room k=3k=3, the trap will activate at the moment 1+s1=1+2=31+s_1=1+2=3, preventing your return (you would attempt to enter room 22 on your way back at second 33, but the activated trap would block you). Any larger value for kk is also not feasible. Thus, the answer is k=2k=2.

你位于一条向右无限延伸的走廊中,走廊被划分为若干个正方形房间。你从第 11 个房间出发,前往第 kk 个房间,再返回第 11 个房间。你可以自由选择 kk 的值。每次移动到相邻房间耗时 11 秒。

此外,走廊中存在 nn 个陷阱:第 ii 个陷阱位于第 did_i 个房间,并在你进入房间 di\boldsymbol{d_i} 后 sis_i 秒被触发。一旦陷阱被触发,你就无法再进入或离开带有该陷阱的房间。

走廊及你前往房间 kk 并返回路径的一种示意图。

请确定最大的 kk 值,使得你能安全地从房间 11 出发到达房间 kk,再返回房间 11。

例如,若 n=1n=1,且 d1=2, s1=2d_1=2,\, s_1=2,则你可以安全地前往房间 k=2k=2 并返回(陷阱将在时刻 1+s1=1+2=31+s_1=1+2=3 触发,此时你早已返回,因此不影响返程)。但若尝试到达房间 k=3k=3,陷阱仍会在时刻 1+s1=1+2=31+s_1=1+2=3 触发,从而阻碍你返程(你在返程途中将于第 33 秒重新进入房间 22,而此时陷阱已激活,将阻止你通行)。任何更大的 kk 值也同样不可行。因此答案为 k=2k=2。

输入格式

The first line of the input contains an integer tt (1≤t≤10001 \le t \le 1000) — the number of test cases.

The descriptions of the test cases follow.

The first line of each test case description contains an integer nn (1≤n≤1001 \le n \le 100) — the number of traps.

The following nn lines of each test case description present two integers did_i and sis_i (1≤di,si≤2001 \le d_i, s_i \le 200) — the parameters of a trap (you must leave room did_i strictly before sis_i seconds have passed since entering this room). It's possible for multiple traps to occupy a single room (the values of did_i can be repeated).

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。

随后是各测试用例的描述。

每个测试用例描述的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100),表示陷阱的数量。

每个测试用例描述的接下来 nn 行,每行包含两个整数 did_i 和 sis_i(1≤di,si≤2001 \le d_i, s_i \le 200),表示一个陷阱的参数(你必须在进入该房间后的 sis_i 秒严格过去之前,留出 did_i 的空间)。多个陷阱可能位于同一房间中(即 did_i 的值可能重复)。

输出格式

For each test case, print the maximum value of kk that allows you to travel to room kk and return to room 11 without encountering an active trap.

对于每个测试用例,输出最大的 kk 值,使得你可以前往房间 kk 并返回房间 11,且途中不触发任何活跃陷阱。

输入输出样例

  • 输入#1

    7
    1
    2 2
    3
    2 8
    4 3
    5 2
    1
    200 200
    4
    1 20
    5 9
    3 179
    100 1
    2
    10 1
    1 18
    2
    1 1
    1 2
    3
    1 3
    1 1
    1 3

    输出#1

    2
    5
    299
    9
    9
    1
    1

说明/提示

The first test case is explained in the problem statement above.

In the second test case, the second trap prevents you from achieving k≥6k\ge6. If k≥6k\ge6, the second trap will activate at the moment 3+s2=3+3=63+s_2=3+3=6 (the time you enter room 44 plus s2s_2). In the case of k≥6k\ge6, you will return to room 44 at time 77 or later. The trap will be active at that time. It can be shown that room k=5k=5 can be reached without encountering an active trap.

In the third test case, you can make it to room 299299 and then immediately return to room 11.

第一个测试用例已在题目描述中说明。

在第二个测试用例中,第二个陷阱阻止你达到 k≥6k\ge6。若 k≥6k\ge6,则第二个陷阱将在时刻 3+s2=3+3=63+s_2=3+3=6 触发(即你进入房间 44 的时刻加上 s2s_2)。当 k≥6k\ge6 时,你将在时刻 77 或更晚返回房间 44,此时该陷阱处于激活状态。可以证明:房间 k=5k=5 可以在不遭遇任何激活陷阱的情况下到达。

在第三个测试用例中,你可以抵达房间 299299,然后立即返回房间 11。

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

首页