Logo
(追記) (追記ここまで)

19327번 - Elevator 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB38242161.765%

문제

You have a very important job: you are responsible for an elevator in the new skyscraper.

There are $n$ persons who will come to the underground parking located on floor 0ドル$ and wait for an elevator to bring them to some upper floor. Formally, $i$-th person comes to the elevator at moment $t_i$ and wants to reach floor $a_i$. The elevator has infinite capacity; that is, there is no limit on the number of people using the elevator at any moment. All numbers $t_i$ are distinct. Passengers always enter the elevator as long as it is at floor 0ドル$.

The elevator uses the following algorithm: it stays open on floor 0ドル$ until you send it to deliver passengers, then it moves to the highest floor it needs (the maximum $a_i$ among all passengers who are currently in the elevator), distributing the passengers in the process, and returns to the parking. The elevator spends 1ドル$ unit of time to move to the next floor (or to the previous floor). The time spent for opening and closing the doors of the elevator, as well as for the passengers entering and leaving the elevator, is negligible. At moment 0ドル,ドル the elevator is at floor 0ドル$.

You want to minimize the moment of time when the elevator will return to floor 0ドル$ after delivering everyone.

입력

The input contains one or more test cases.

The first line of each test case contains one integer $n$: the number of passengers (1ドル \le n \le 2 \cdot 10^5$).

Each of the following $n$ lines contains two space-separated integers $t_i$ and $a_i$: the moment of time when $i$-th passenger comes to the elevator, and the destination floor of $i$-th passenger (1ドル \le t_i, a_i \le 10^9$).

All $t_i$ in one test case are distinct, passengers appear in input in ascending order of $t_i$.

The sum of the values of $n$ over all test cases does not exceed 2ドル \cdot 10^5$. The test cases just follow one another without any special separators.

출력

For each test case, print one integer: the minimum possible moment of time when the elevator will return after delivering all passengers.

제한

예제 입력 1

3
1 9
2 6
15 6
3
1 9
2 6
15 8

예제 출력 1

31
33

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 8: Saratov SU Contest D번

Contest > Open Cup > 2017/2018 Season > Stage 13: Grand Prix of Saratov D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /