J2. Dusa And The Yobis
의견: 0
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.
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.
5
3
2
9
20
22
1419Dusa is large enough to eat the Yobi of size \(3\). This brings Dusa’s size to \(8\). Dusa is large enough to eat the Yobi
of size \(2\). This brings Dusa’s size
to \(10\). Dusa is large enough to eat
the Yobi of size \(9\). This brings
Dusa’s size to \(19\). The Yobi of size
\(20\) causes Dusa to run away.
10
10
3
510The Yobi of size \(10\) causes Dusa
to run away, leaving its size unchanged.
평가 및 의견
J2. Dusa And The Yobis
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
J2. Dusa And The Yobis