Advertisement
Ne-Biolog

Untitled

Feb 4th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. //#include <bits/stdc++.h>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <vector>
  6. #include <cmath>
  7. #include <cstdio>
  8. #include <set>
  9.  
  10. #define DEBUG 1
  11. #define TIME clock() / 1.0 / CLOCKS_PER_SEC
  12.  
  13. using namespace std;
  14.  
  15. signed main()
  16. {
  17. #if DEBUG
  18. freopen("input.txt", "r", stdin);
  19. freopen("output.txt" , "w", stdout);
  20. ios_base::sync_with_stdio(false);
  21. #endif
  22.  
  23. int n;
  24. cin >> n;
  25. int *a = new int [n + 1];
  26. int *sum = new int [n + 1];
  27. int *mn = new int [n + 1];
  28. sum[0] = 0;
  29. for(int i = 1; i <= n; ++i) {
  30. cin >> a[i];
  31. sum[i] = sum[i - 1] + a[i];
  32. }
  33. mn[0] = 0;
  34. for(int i = 1; i <= n; ++i) {
  35. mn[i] = min(mn[i - 1], sum[i]);
  36.  
  37. }
  38. int ans = -1111111111;
  39. for(int i = 1; i <= n; ++i) {
  40. ans = max(ans, sum[i] - mn[i - 1]);
  41. }
  42.  
  43. cout << ans << endl;
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement