Source Code
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    long long ans = 0;
    long long 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 Mohamedmaher
GNU G++17
39 ms
988 KB
Accepted