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+=l;}
     
 }
 cout<<l;
}
Copy
Zeina The Business Owner Joud
GNU G++17
3 ms
668 KB
Wrong Answer