josiftepe

Untitled

Oct 24th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10.     ios_base::sync_with_stdio(false);
  11.     int n;
  12.     cin >> n;
  13.     vector<long long> v(n);
  14.     for(long long &x : v) {
  15.         cin >> x;
  16.     }
  17.     vector<long long> dp(n, 0);
  18.     dp[0] = v[0];
  19.     long long ret = v[0];
  20.     for(int i = 1; i < n; ++i) {
  21.         dp[i] = max(dp[i - 1] + v[i], v[i]);
  22.         ret = max(ret, dp[i]);
  23.     }
  24.     cout << ret << endl;
  25.     return 0;
  26. }
  27.  
  28.  
  29.  
  30. /*
  31.  10
  32.  404 882
  33.  690 974
  34.  201 255
  35.  800 933
  36.  525 819
  37.  457 601
  38.  461 978
  39.  832 932
  40.  699 804
  41.  795 860
  42.  */
  43.  
Advertisement
Add Comment
Please, Sign In to add comment