Dusa And The Yobis | 프로그래밍의 벗 PivotOJ
PivotOJ

Dusa And The Yobis

시간 제한: 1000ms메모리 제한: 1024MB출처: CCC 2024 JuniorBOJ 32327
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Dusa eats Yobis, but only Yobis of a certain size.

If Dusa encounters a Yobi that is smaller than itself, it eats the Yobi, and absorbs its size. For example, if Dusa is of size 10 and it encounters a Yobi of size 6, Dusa eats the Yobi and expands to size 10 + 6 = 16.

If Dusa encounters a Yobi that is the same size as itself or larger, Dusa runs away without eating the Yobi.

Dusa is currently facing a line of Yobis and will encounter them in order. Dusa is guaranteed to eventually encounter a Yobi that causes it to run away. Your job is to determine Dusa’s size when this happens.

[이미지 1]

입력

The first line of input contains a positive integer, D, representing Dusa’s starting size.

The remaining lines of input contain positive integers representing the sizes of the Yobis in order.

출력

Output the positive integer, R, which is Dusa’s size when it eventually runs away.

예제

예제 1

입력
5
3
2
9
20
22
14
출력
19

예제 2

입력
10
10
3
5
13
출력
10
코드를 제출하려면 로그인하세요.