Advertisement
Josif_tepe

Untitled

May 28th, 2024
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF = 2e9;
  4. int main()
  5. {
  6.    int n;
  7.    cin >> n;
  8.  
  9.    vector<int> v(n), dp(n);
  10.    for(int i = 0; i < n; i++) {
  11.     cin >> v[i];
  12.     dp[i] = v[i];
  13.    }
  14.  
  15.    for(int i = 1; i < n; i++) {
  16.     dp[i] = max(dp[i - 1] + v[i], dp[i]);
  17.    }
  18.     int res = -INF;
  19.     for(int i = 0; i < n; i++) {
  20.         res = max(res, dp[i]);
  21.     }
  22.     cout << res << endl;
  23.     return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement