#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> arr(n + 5);
for (int i = 1; i <= n; i++) cin >>arr[i];
vector<vector<int>> dp(n + 5, vector<int>(k + 5, 1e18));
map<int, int> mn;
//for (int i = 0; i <= k; i++) mn[i] = 0;
mn[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
/*for (int l = 1; l <= i; l++) {
dp[i][j] = min(dp[i][j], dp[l - 1][j - 1] + arr[i] - arr[l] + 1);
}*/
dp[i][j] = min(dp[i][j], arr[i] + mn[j - 1]);
mn[j] = min(mn[j], dp[i - 1][j] - arr[i] + 1);
}
}
cout << dp[n][k] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 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 |
212 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 |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |