'commit'
This commit is contained in:
31
TangDou/CSP-J/AcWingTraining/T6/126_YiWei.cpp
Normal file
31
TangDou/CSP-J/AcWingTraining/T6/126_YiWei.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user