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;
#define ll int
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second
const ll N = 5003;
ll n,k;
pii q[N];
ll a[N],memo[N][N];
ll dp(ll x, ll y) {
if(x == n+1) return 0;
ll temp = memo[x][y];
if(temp != -1) return temp;
temp = dp(x+1,y);
if(a[x] >= y) {
temp = max(temp,dp(x+1,a[x])+1);
}
return memo[x][y] = temp;
}
int main() {
memset(memo,-1,sizeof(memo));
cin >> n >> k;
for(int i=1; i<=n; i++) {
cin >> q[i].fi;
q[i].se = i;
}
sort(q+1,q+n+1);
for(int i=1; i<=n; i++) {
a[q[i].se] = (i-1)/k + 1;
}
cout << n - dp(1,0) << 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |