fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl "\n"
  5. #define fast ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  6. #define pb push_back
  7. #define yes cout<<"YES"<<endl
  8. #define no cout<<"NO"<<endl
  9. #define F first
  10. #define S second
  11. #define C continue
  12. #define R return
  13. const ll N=5e5+9;
  14. const ll mod=1e9+7;
  15. const ll oo=1e18;
  16. const ll M=1e6+10;
  17. ll T,n,a[N],sum,mx;
  18. int main()
  19. {
  20. fast
  21. //freopen("input.in","r",stdin) ;
  22. //freopen("output.txt","w",stdout);
  23. T=1;
  24. //cin>>T;
  25. while(T--)
  26. {
  27. cin>>n;
  28. sum=mx=0;
  29. int f=0;
  30. for(int i=1;i<=n;i++){
  31. cin>>a[i];
  32. if(a[i]<0) f++;
  33. if(sum+a[i]<0)sum=0;
  34. else sum+=a[i];
  35. mx=max(mx,sum);
  36. }
  37. if(f==n) mx=*max_element(a+1,a+n+1);
  38. cout<<mx;
  39. }
  40. return 0;
  41. }
  42.  
  43. /*
  44.  
  45.  
  46. */
  47.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty