Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int N = 1e6 + 5;
- const int mod = 1e9 + 7;
- const int INF = 1e18;
- int a[N];
- int dp[N];
- signed main()
- {
- int n;
- cin >> n;
- for(int i = 0; i < n; i++){
- cin >> a[i];
- }
- int m = 0;
- dp[0] = a[0];
- for(int i = 1; i < n; i++){
- dp[i] = m + a[i];
- m = max(m , dp[i - 1]);
- }
- int ans = 0;
- for(int i = 0; i < n; i++){
- ans = max(ans , dp[i]);
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement