You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
467 B

#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, a[N], s[N], ans[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], s[i] = s[i - 1] + a[i]; // 前缀和
int mi = 0;
for (int i = 1; i <= n; i++) {
ans[i] = s[i] - mi;
mi = min(mi, s[i]);
}
int res = INT_MIN;
for (int i = 1; i <= n; i++) res = max(res, ans[i]);
cout << res << endl;
return 0;
}