Problem list
Log in
#coci00407 · COCI 2016/2017 Contest 1

Tarifa

Bronze III 1.0 s 64 MB

1 $s / 64$ $MB / 50$ points

Pero has negotiated a Very Good data plan with his internet provider. The provider will let

Pero use up X megabytes to surf the internet per month. Each megabyte that he doesn’t

spend in that month gets transferred to the next month and can still be spent. Of course,

Pero can only spend the megabytes he actually has.

If we know how much megabytes Pero has spent in each of the first ​$N$ months of using the

plan, determine how many megabytes Pero will have available in the ​$N$ ​

  • 1 month of using

the plan.

Input

The first line of input contains the integer ​$X$ ​ (1 ≤ ​$X$ ​ ≤ 100). The second line of input contains the integer ​$N$ ​ ​(1 ≤ ​$N$ ​ ≤ 100). Each of the following ​$N$ lines contains an integer ​$P$ ​ _{i} ^{(0} ^{≤}^{​}^{P} ​ _{i} ^{​}^{≤10} ^{000),} ^{the} ^{number} ^{of}

megabytes spent in each of the first ​$N$ months of using the plan. Numbers ​$P$ ​ $i$ ^{will be such that}

Pero will never use more megabytes than he actually has.

Output

The first and only line of output must contain the required value from the task.

Example 1

Input
10
3
4
6
2
10
3
10
2
12
15
3
15
10
20
Output
output
output
28
16
15

Clarification of the first test case: In the first month, out of 10 total megabytes, Pero has spent 4 and transferred 6 into the next month. In

the second month, out of 16 (10+6) total megabytes, Pero has spent 6 and transferred 10. In the third

month, out of 20 (10+10) total megabytes, Pero has spent 2 and transferred 18. In the fourth month, he

had a total of 28 megabytes to spend.

Source
COCI 2016/2017 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code