Source Code

#include <iostream>
using namespace std;

#include <math.h>
int main (){
    int n;
    cin>>n;
    int arr[n];
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    int pre[n] ={0};
    for (int i=0;i<n;i++){
        if (i==0) pre[i] = arr[i];
        else pre[i]+=(pre[i-1]+arr[i]);
    }
    int sum =0;
    for (int i=0;i<n;i++) sum+=pre[i];
    if (sum>0) cout <<0<<endl;
    else {
        if (sum==0) cout <<sum+1<<endl;
        else {
            sum = abs(sum) +1;
            cout <<sum<<endl;
        }
    }
    
    return 0;
}
Copy
Zeina The Business Owner yaman
GNU G++17
2 ms
704 KB
Wrong Answer