Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) x.begin(), x.end()
  3. #define ll long long
  4. #define ld long double
  5. #define pb push_back
  6. #define endl '\n'
  7. #define ff first
  8. #define mp make_pair
  9. #define ss second
  10. #define ull unsigned long long
  11. #define YES cout << "YES" << endl;
  12. #define NO cout << "NO" << endl;
  13. #define ulongmax 18446744073709551615
  14. #define pll pair<ll,ll>
  15. using namespace std;
  16.  
  17. ll maxn = -1e9;
  18. ll minn = 1e9;
  19. ll mod = 1e9 + 7;
  20. const int maxx = 3e6 + 5;
  21. const int base = 311;
  22. ll a[maxx];
  23. int main(){
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(0);
  26. cout.tie(0);
  27. //freopen("HACK.TXT","r",stdin);
  28. //freopen(".INP","r",stdin);
  29. //freopen(".OUT","w",stdout);
  30. //freopen("HACK.TXT","w",stdout);
  31. ll n;
  32. cin >> n;
  33. for (int i = 1; i <= n; i++){
  34. cin >> a[i];
  35. }
  36. ll mn = 0;
  37. ll ans = 0;
  38. ll tong = 0;
  39. for (int i = 1; i <= n; i++){
  40. tong = tong + a[i];
  41. mn = mn + a[i];
  42. if (mn > 0) mn = 0;
  43. if (mn < ans) ans = mn;
  44. }
  45. cout << (-ans) * 2 + tong;
  46. }
  47. /*
  48. 5 2
  49. 1 2
  50. 2 3
  51. 3 4
  52. 1 5
  53. 5 2
  54. 4 1
  55. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement