mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 15:18:46 +00:00
P1115 最大子段和
R72982914
This commit is contained in:
parent
89ef0aac23
commit
eddbb9127d
24
Luogu/P1115/P1115.cpp
Normal file
24
Luogu/P1115/P1115.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e5 + 5;
|
||||
|
||||
int n, f[N], ans = std::numeric_limits<int>::min();
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
for (int i = 1, x; i <= n; i++) {
|
||||
cin >> x;
|
||||
f[i] = std::max(f[i - 1] + x, x);
|
||||
ans = std::max(ans, f[i]);
|
||||
}
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user