시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 69 34 29 55.769%

문제

성실한 농부 존은 시간을 효율적으로 관리해야 한다는 걸 깨달았다. 그는 N개의 해야할 일에 (1<=N<=1000) 숫자를 매겼다. (우유를 짜고, 마굿간을 치우고, 담장을 고치는 등의)

존의 시간을 효율적으로 관리하기 위해, 그는 끝내야만 하는 일 목록을 만들었다. 완성될 때 필요한 시간을 T_i(1<=T_i<=1,000) 라고 하며, 끝내야하는 시간을 S_i(1<=S_i<=1,000,000) 이라 한다. 농부 존은 하루의 시작을 t = 0으로 정했다. 그리고 일 할 때는 그 일을 마칠 때 까지 그 일만 한다. 

존은 늦잠 자는 걸 좋아한다. 따라서 제 시간에 끝낼 수 있게 결정할 수 있는 한도에서 존이 가장 늦게 일어나도 되는 시간을 출력하라.

입력

첫 줄에는 일의 개수인 N을 받고

두 번째 줄부터 N+1줄까지 T_i와 S_i를 입력받는다. 

출력

존이 일을 할 수 있는 마지막 시간을 출력 하라. 존이 제시간에 일을 끝낼 수 없다면 -1 을 출력하라.

예제 입력 1

4
3 5
8 14
5 20
1 16

예제 출력 1

2
W3sicHJvYmxlbV9pZCI6IjYwNjgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWMyZGNcdWFjMDQgXHVhZDAwXHViOWFjXHVkNTU4XHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cdWMxMzFcdWMyZTRcdWQ1NWMgXHViMThkXHViZDgwIFx1Yzg3NFx1Yzc0MCBcdWMyZGNcdWFjMDRcdWM3NDQgXHVkNmE4XHVjNzI4XHVjODAxXHVjNzNjXHViODVjIFx1YWQwMFx1YjlhY1x1ZDU3NFx1YzU3YyBcdWQ1NWNcdWIyZTRcdWIyOTQgXHVhYzc4IFx1YWU2OFx1YjJlY1x1YzU1OFx1YjJlNC4gXHVhZGY4XHViMjk0IE5cdWFjMWNcdWM3NTggXHVkNTc0XHVjNTdjXHVkNTYwIFx1Yzc3Y1x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aWNoIHRha2UgMywgOCwgNSwgYW5kIDEgdW5pdHMgb2YgdGltZSwgcmVzcGVjdGl2ZWx5LCBhbmQgbXVzdCBiZSBjb21wbGV0ZWQgYnkgdGltZSA1LCAxNCwgMjAsIGFuZCAxNiwgcmVzcGVjdGl2ZWx5LjxcL3A+XHJcblxyXG48cD5GYXJtZXIgSm9obiBtdXN0IHN0YXJ0IHRoZSBmaXJzdCBqb2IgYXQgdGltZSAyLiBUaGVuIGhlIGNhbiBkbyB0aGUgc2Vjb25kLCBmb3VydGgsIGFuZCB0aGlyZCBqb2JzIGluIHRoYXQgb3JkZXIgdG8gZmluaXNoIG9uIHRpbWUuPFwvcD5cclxuXHJcbjxwPiZuYnNwOzxcL3A+XHJcbiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

Olympiad > USA Computing Olympiad > 2008-2009 Season > USACO November 2008 Contest > Silver 3번

  • 문제를 번역한 사람: inspire12
  • 문제의 오타를 찾은 사람: isku