anon20016

E

Nov 18th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. #define ull unsigned long long
  11. #define ll long long
  12.  
  13. using namespace std;
  14.  
  15. ll a[100001];
  16. ll d[100001];
  17.  
  18. int main() {
  19. //freopen("input.txt", "r", stdin);
  20. //freopen("output.txt", "w", stdout);
  21. int n;
  22. cin >> n;
  23. for (int i = 0; i < n; i++) {
  24. cin >> a[i];
  25. }
  26. d[0] = a[0];
  27. d[1] = a[1];
  28. ll mx = max(a[0], 0ll);
  29. for (int i = 2; i < n; i++) {
  30. d[i] = a[i] + mx;
  31. mx = max(mx, d[i - 1]);
  32. }
  33. mx = max(mx, d[n - 1]);
  34. cout << mx;
  35.  
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment