#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
#define ll long long
void solve() {
// dp[i][j] = the max sum that can be obtained if j subsegments are chosen and last subsegment ends at i
// dp[i][j] = dp[0..i][j-1]
int n, k; cin >> n >> k;
vector<ll int> arr(n); for (int i = 0; i < n; i++) {
cin >> arr[i];
}
vector<vector<ll int>> dp(n + 1, vector<ll int>(k + 1));
ll int ans = 0;
ll int mn = 0;
ll int pref = 0;
for (int i = 0; i < n; i++) {
pref += arr[i];
mn = min(pref, mn);
dp[i][1] = max(pref - mn, pref);
ans = max(ans, dp[i][1]);
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
19756 KB |
Output is correct |
2 |
Correct |
39 ms |
20184 KB |
Output is correct |
3 |
Correct |
35 ms |
19660 KB |
Output is correct |
4 |
Runtime error |
124 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
21820 KB |
Output is correct |
2 |
Correct |
52 ms |
21604 KB |
Output is correct |
3 |
Correct |
53 ms |
21820 KB |
Output is correct |
4 |
Correct |
65 ms |
21612 KB |
Output is correct |
5 |
Correct |
53 ms |
21820 KB |
Output is correct |
6 |
Correct |
51 ms |
21964 KB |
Output is correct |
7 |
Correct |
52 ms |
21972 KB |
Output is correct |
8 |
Correct |
56 ms |
21736 KB |
Output is correct |
9 |
Correct |
52 ms |
22032 KB |
Output is correct |
10 |
Correct |
50 ms |
21964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |