Source Code
#include<iostream>
#include<algorithm>
using namespace std ;
int main()
{
  int n, p=0 ,l = 0  ;
  cin>>n;

  int arr[n];
  for(int i = 0 ; i<n ; i++)
 {
     cin>>arr[i];
     
     p += arr[i];
    
     if(p <=0 ) {l+=abs(p)+1; p+=(abs(p)+1);}
   

 }
 cout<<l;
}
Copy
Zeina The Business Owner Joud
GNU G++17
23 ms
1.3 MB
Accepted