Files
python/TangDou/CSP-J/AcWingTraining/T6/126_YiWei.cpp

32 lines
518 B
C++
Raw Permalink Normal View History

2025-08-30 18:35:01 +08:00
#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;
}