cswork / OAOpen practice workspace

UberOA #22

Character Health in a Video Game

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

The initial health is between 0 and 100. Add each change in order, clamping the result to [0,100] after every step, and output the final value.

This site's standard input/output is stated explicitly.

Input

The first line contains n initial, and the second line contains n changes. On this site n is 0..100000, initial is 0..100, and changes are −10⁹..10⁹.

Output

Output one integer answer.

Example 1

Input:

4 12
-4 -12 6 2

Output:

8

Example 2

Input:

2 95
20 -10

Output:

90

Example 3

Input:

0 10

Output:

10

Example notes

Example 1: the health goes 8, 0, 6, 8, so the output is 8. Example 2: it first reaches the cap of 100 and then loses 10, so the output is 90. Example 3: with no changes, it stays at 10.

Editorial

Loading solution…