Advertisement
Guest User

Untitled

a guest
May 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. const int N = 1e5;
  6. int a[N], pref[N], pm[N];
  7. int n;
  8.  
  9. void precalc(){
  10. pref[0] = a[0];
  11. pm[0] = pref[0];
  12. for(int i = 1; i < n; i++)
  13. {
  14. pref[i] = pref[i-1] + a[i];
  15. pm[i] = min(pm[i-1], pref[i]);
  16. }
  17. }
  18.  
  19. int32_t main()
  20. {
  21. ios_base::sync_with_stdio(0);
  22. //cout.precision(18);
  23. /*
  24. freopen("input.txt", "r", stdin);
  25. freopen("output.txt", "w", stdout);
  26. */
  27. cin >> n;
  28. for(int i = 0; i < n; i++)
  29. cin >> a[i];
  30. precalc();
  31. int ans = 0;
  32. for(int i = 0; i < n; i++)
  33. ans = max(ans, pref[i] - min(pm[i], 0LL));
  34. cout << ans;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement