Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- const int N = 1e5;
- int a[N], pref[N], pm[N];
- int n;
- void precalc(){
- pref[0] = a[0];
- pm[0] = pref[0];
- for(int i = 1; i < n; i++)
- {
- pref[i] = pref[i-1] + a[i];
- pm[i] = min(pm[i-1], pref[i]);
- }
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(0);
- //cout.precision(18);
- /*
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- */
- cin >> n;
- for(int i = 0; i < n; i++)
- cin >> a[i];
- precalc();
- int ans = 0;
- for(int i = 0; i < n; i++)
- ans = max(ans, pref[i] - min(pm[i], 0LL));
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement