CCC '24 J2 - Dusa And The Yobis

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 3.0s
Memory limit: 1G

Problem types
Canadian Computing Competition: 2024 Stage 1, Junior #2

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.

Input Specification

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 Specification

Output the positive integer, R, 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 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.

Sample Input 2

10
10
3
5
13

Output for Sample Input 2

10

Explanation of Output for Sample Input 2

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


Comments


  • 0
    liyouyan0525  commented on Dec. 11, 2024, 5:21 a.m.

    wtf, why we need except???!!!:(


  • -23
    NotG4y124  commented on July 17, 2024, 7:12 p.m. edit 3

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 3
      petlop222  commented on July 17, 2024, 10:31 p.m.

      please dont put answers in the comments (i think this is solution idk)


  • 1
    Jwwaniem  commented on July 9, 2024, 5:34 p.m.

    how many inputs do we need


    • 0
      Math_competition_pro_  commented on Oct. 27, 2024, 6:10 p.m.

      use a while true loop bc we don't know when duza runs away


    • 1
      htoshiro  commented on July 10, 2024, 9:27 p.m.

      while dusa can eat the yobis


  • -2
    rfasta  commented on July 3, 2024, 11:38 a.m.

    us python users are having a hard time


  • 0
    IsaZhou  commented on May 18, 2024, 10:43 a.m.

    Is there any test case where Dusa can eat all the Yobis?


    • 6
      b_nary  commented on May 18, 2024, 6:38 p.m.

      No, because Dusa is guaranteed to eventually encounter a Yobi that causes it to run away