This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template <typename T> using ve = vector<T>;
template <typename T, int sz> using ar = array<T, sz>;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define endl '\n'
int main() {
int N, K;
cin >> N >> K;
int ti[22] = {};
for(int i = 0; i < N; i++) {
int x;
cin >> x;
ti[x] = 1;
}
int dp[22][22][2];
for(int i = 0; i < 22; i++) {
for(int j = 0; j < 22; j++) {
dp[i][j][0] = (int)1e9;
dp[i][j][1] = (int)1e9;
}
}
for(int i = 21; i >= 1; i--) {
if(ti[i]) {
break;
}
for(int k = 0; k <= K; k++) {
dp[i][k][0] = 0;
}
}
for(int i = 21; i >= 1; i--) {
for(int left = K; left >= 1; left--) {
// ON
if(ti[i]) {
for(int j = i + 1; j <= 21; j++) {
dp[i][left][1] = min(dp[i][left][1], dp[j][left - 1][0] + j - i);
}
} else {
for(int j = i + 1; j <= 21; j++) {
if(ti[j] == 1) {
dp[i][left][0] = min(dp[i][left][0], dp[j][left][1]);
break;
}
}
}
}
}
cout << min(dp[1][K][0], dp[1][K][1]) << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |