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
508 B
19 lines
508 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
const int N = 200010;
|
|
const int INF = 0x3f3f3f3f;
|
|
int res = -INF;
|
|
int a[N];
|
|
int n;
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
for (int i = 1; i <= n; i++) //枚举起点
|
|
for (int j = i; j <= n; j++) { //枚举终点
|
|
int sum = 0;
|
|
for (int k = i; k <= j; k++) sum += a[k]; //区间内的和
|
|
res = max(res, sum);
|
|
}
|
|
cout << res << endl;
|
|
return 0;
|
|
} |