CF1872B.The Corridor or There and Back Again
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are in a corridor that extends infinitely to the right, divided into square rooms. You start in room 1 , proceed to room k , and then return to room 1 . You can choose the value of k . Moving to an adjacent room takes 1 second.
Additionally, there are n traps in the corridor: the i -th trap is located in room di and will be activated si seconds after you enter the room di . 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 k and back.Determine the maximum value of k that allows you to travel from room 1 to room k and then return to room 1 safely.
For instance, if n=1 and d1=2,s1=2 , you can proceed to room k=2 and return safely (the trap will activate at the moment 1+s1=1+2=3 , it can't prevent you to return back). But if you attempt to reach room k=3 , the trap will activate at the moment 1+s1=1+2=3 , preventing your return (you would attempt to enter room 2 on your way back at second 3 , but the activated trap would block you). Any larger value for k is also not feasible. Thus, the answer is k=2 .
输入格式
The first line of the input contains an integer t ( 1≤t≤1000 ) — the number of test cases.
The descriptions of the test cases follow.
The first line of each test case description contains an integer n ( 1≤n≤100 ) — the number of traps.
The following n lines of each test case description present two integers di and si ( 1≤di,si≤200 ) — the parameters of a trap (you must leave room di strictly before si seconds have passed since entering this room). It's possible for multiple traps to occupy a single room (the values of di can be repeated).
输出格式
For each test case, print the maximum value of k that allows you to travel to room k and return to room 1 without encountering an active trap.
输入输出样例
输入#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≥6 . If k≥6 , the second trap will activate at the moment 3+s2=3+3=6 (the time you enter room 4 plus s2 ). In the case of k≥6 , you will return to room 4 at time 7 or later. The trap will be active at that time. It can be shown that room k=5 can be reached without encountering an active trap.
In the third test case, you can make it to room 299 and then immediately return to room 1 .