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.

19 lines
478 B

#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int INF = 0x3f3f3f3f;
int n, a[N], res = -INF;
int sum[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i]; //输入
sum[i] = sum[i - 1] + a[i]; //记录前缀和
}
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++)
res = max(res, sum[j] - sum[i - 1]);
cout << res << endl;
return 0;
}