Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int a[10000010], dp[10000010];
- int main(){
- int n;
- cin >> n;
- for(int i=0; i<n; i++) cin >> a[i];
- for(int i=0; i<n; i++)
- dp[i] = max(0, dp[i-1] + a[i]);
- bool all_neg = true;
- for(int i=0; i<n; i++) if(a[i] >= 0) all_neg = false;
- if(all_neg) cout << *max_element(a, a+n) << endl;
- else cout << *max_element(dp, dp+n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement