描述
题解
逐个处理,当energy
小于0时,res
就加上-energy
,最后直接出结果。一道水题。
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main(int argc, const char * argv[])
{
//freopen("input.txt", "r", stdin);
int n;
cin >> n;
long long A;
long long res = 0;
long long energy = 0;
for (int i = 0; i < n; i++)
{
scanf("%lld", &A);
energy += A;
if (energy < 0)
{
res += -energy;
energy = 0;
}
}
cout << res << '\n';
return 0;
}