'commit'
This commit is contained in:
20
TangDou/Topic/PrefixAndSuffix/P1115_Prefix.cpp
Normal file
20
TangDou/Topic/PrefixAndSuffix/P1115_Prefix.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 200100;
|
||||
int n, a[N], s[N], ans[N];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
cin >> a[i], s[i] = s[i - 1] + a[i]; // 前缀和
|
||||
|
||||
int mi = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
ans[i] = s[i] - mi;
|
||||
mi = min(mi, s[i]);
|
||||
}
|
||||
int res = INT_MIN;
|
||||
for (int i = 1; i <= n; i++) res = max(res, ans[i]);
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user