Source Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    ll ans = 0;
    ll sum = 0;
    for (int i = 0, x; i < n; ++i) {
        cin >> x;
        sum += x;
        if (sum <= 0) {
            ans += -sum + 1;
            sum = 1;
        }
    }
    cout << ans << '\n';
    return 0;
}
Copy
Zeina The Business Owner Heartbeat
GNU G++17
9 ms
1.0 MB
Accepted