#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, k, arr[100010];
pair<ll, ll> dp[100010][110];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=0; i<100010; i++) {
for(int j=0; j<110; j++) {
dp[i][j] = {1e9, 1e9};
}
}
dp[1][1] = {arr[1], arr[1]};
for(int i=1; i<n; i++) {
for(int j=1; j<=k; j++) {
if(j > i) continue;
if(dp[i+1][j+1].first > dp[i][j].first + arr[i+1]) {
dp[i+1][j+1].first = dp[i][j].first + arr[i+1];
dp[i+1][j+1].second = arr[i];
}
if(dp[i+1][j].first > dp[i][j].first + arr[i+1]) {
dp[i+1][j].first = dp[i][j].first;
if(dp[i+1][j].second < arr[i+1]) {
dp[i+1][j].first += arr[i+1] - dp[i+1][j].second;
dp[i+1][j].second = arr[i+1];
}
}
}
}
cout << dp[n][k].first;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
172488 KB |
Output is correct |
2 |
Correct |
76 ms |
172628 KB |
Output is correct |
3 |
Incorrect |
67 ms |
172664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
172580 KB |
Output is correct |
2 |
Correct |
66 ms |
172544 KB |
Output is correct |
3 |
Incorrect |
69 ms |
172428 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
172488 KB |
Output is correct |
2 |
Correct |
76 ms |
172628 KB |
Output is correct |
3 |
Incorrect |
67 ms |
172664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
172488 KB |
Output is correct |
2 |
Correct |
76 ms |
172628 KB |
Output is correct |
3 |
Incorrect |
67 ms |
172664 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |