시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB30721617870.356%

문제

LEDs are an amazing technology, in part due to their longevity. But they can’t last forever right? So you decide to put it to the test; you turn on an LED, and a machine periodically records the time in milliseconds since you started. Eventually it turns off! Your machine kept recording though, and unforunately your data is all jumbled up! What is the first time the machine recorded the LED being off?

Note that the LED may turn back on; you want to find the very first time the LED was recorded being off.

입력

The first line of input contains the integer $N$ ($1≤N≤10^5$). The following $N$ lines consist of $2$ integers $M$ ($0≤M<2^{31}$) and $O$ ($O\in\{0,1\}$), where $M$ is the time this recording was taken in milliseconds, and $O$ denotes whether the LED was on or off. The number $1$ corresponds to the LED being on, and $0$ off.

출력

Output a single integer denoting the time of the first recording where the LED was off, or output $-1$ if it was never off for any recording.

예제 입력 1

4
400 0
100 1
300 0
200 1

예제 출력 1

300

예제 입력 2

3
10 1
2010 1
150 1

예제 출력 2

-1

예제 입력 3

6
250 0
25 1
100 0
50 0
200 1
150 1

예제 출력 3

50

출처

University > University of Alberta Programming Contest > UAPC 2025 > Division 2 B번

  • 문제를 만든 사람: Noah Gergel