CCCGuide

Problem J2: Dusa And The Yobis

2024 · J2 · Original problem · DMOJ

Problem Description

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 1010 and it encounters a Yobi of size 66, Dusa eats the Yobi and expands to size 10+6=1610+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.

    

Input Specification

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

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

Output Specification

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

Sample Input 1

5
3
2
9 
20
22
14

Output for Sample Input 1

19

Explanation of Output for Sample Input 1

Dusa is large enough to eat the Yobi of size 33. This brings Dusa’s size to 88. Dusa is large enough to eat the Yobi of size 22. This brings Dusa’s size to 1010. Dusa is large enough to eat the Yobi of size 99. This brings Dusa’s size to 1919. The Yobi of size 2020 causes Dusa to run away.

Sample Input 2

10
10
3
5

Output for Sample Input 2

10

Explanation of Output for Sample Input 2

The Yobi of size 1010 causes Dusa to run away, leaving its size unchanged.