Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int INF = 2e9;
- int main()
- {
- int n;
- cin >> n;
- vector<int> v(n), dp(n);
- for(int i = 0; i < n; i++) {
- cin >> v[i];
- dp[i] = v[i];
- }
- for(int i = 1; i < n; i++) {
- dp[i] = max(dp[i - 1] + v[i], dp[i]);
- }
- int res = -INF;
- for(int i = 0; i < n; i++) {
- res = max(res, dp[i]);
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement