IME Starters Try-outs 2018
A - Adaptation Stories
During the military adaptation period, the candidate DH forgot to bring his water bottle to drill. So that he would not run out of water, the military training leaders lent him a water gallon, affectionately called by minalbinha. However it should also be used to resupply the water bottle of the other candidates.
During the training, the military training leaders will bring some amount of water to refill minalbinha and the other candidates will take some amount of water from minalbinha to refill their bottles.
DH, being the responsible for minalbinha, knows the order and the amount of water of every request. He asked your help to determine the minimum amount of water needed to bring on minalbinha so that every request can be satisfied.
Consider that minalbinha can carry any amount of water.
Input
The first line of input contains one integer, nn (0≤n≤1050≤n≤105) — the number of requests.
The next line contains nn integers, vivi (−1000≤vi≤1000−1000≤vi≤1000, vi≠0vi≠0) — the amount of water of ii-th request. If vivi is negative, the water is being taken from minalbinha, otherwise the water is being given to minalbinha.
Output
Print the minimum amount of water that is needed to bring on minalbinha to fulfill all requests.
Examples
Input
7 2 1 -1 -4 3 -5 3
Output
4
Input
3 10 3 -10
Output
0
Input
3 -10 -10 -10
Output
30
水题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int now,m,n,a[100005];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
now+=a[i];
m=min(now,m);
}
m=-m;
printf("%d\n",m);
return 0;
}