Advertisement
Josif_tepe

Untitled

Nov 2nd, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n;
  7.     cin >> n;
  8.     vector<int> v(n);
  9.     for(int i = 0; i < n; i++) {
  10.         cin >> v[i];
  11.     }
  12.     vector<int> sum(n);
  13.     sum[0] = v[0];
  14.    
  15.     for(int i = 1; i < n; i++) {
  16.         sum[i] = max(v[i], sum[i - 1] + v[i]);
  17.     }
  18.     cout << *max_element(sum.begin(), sum.end()) << endl;
  19.     return 0;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement