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.

32 lines
518 B

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int a[N], s[N];
int f[N];
/*
7
5 -2 -4 8 -1 5 4
输出:
16
*/
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i]; // 累加出前缀和
}
int res = -INF;
for (int i = 1; i <= n; i++) {
f[i] = max(f[i - 1], 0) + a[i];
res = max(res, f[i]);
}
cout << res << endl;
return 0;
}