Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main(){
- int n;
- cin >> n;
- vector<int> v(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- }
- vector<int> sum(n);
- sum[0] = v[0];
- for(int i = 1; i < n; i++) {
- sum[i] = max(v[i], sum[i - 1] + v[i]);
- }
- cout << *max_element(sum.begin(), sum.end()) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement