fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e6+14;
  4. long long n, sum = 0, minres = 0, ans = -1e18;
  5. void solve(){
  6. cin >> n;
  7. for (int i = 1; i <= n; i++){
  8. int x;
  9. cin >> x;
  10. minres = min(minres, sum);
  11. sum += x;
  12. ans = max(ans, sum - minres);
  13. }
  14.  
  15. cout << ans;
  16. }
  17. int main(){
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0); cout.tie(0);
  20. if (fopen("input.txt","r")) {
  21. freopen("input.txt","r",stdin);
  22. freopen("output.txt","w",stdout);
  23. }
  24. solve();
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
-1000000000000000000