#include<bits/stdc++.h>
using namespace std;
int test;
int n;
int k;
int dp[5005];
pair<int,int> B[5005];
int A[5005];
int main(){
cin >> n;
cin >> k;
for(int i=0; i<n; i++)
{
int v;
cin >> v;
B[i]={v,i};
}
sort(B,B+n);
int group=0;
int cnt=0;
for(int i=0; i<n; i++)
{
A[B[i].second]=group;
cnt++;
if(cnt==k)
{
cnt=0;
group++;
}
}
dp[0]=1;
int maxi;
int ans=0;
for(int i=1; i<n; i++)
{
maxi=i;
for(int j=0; j<i; j++)
{
if(A[j]<=A[i] && dp[j]>dp[maxi])
{
maxi=j;
}
}
dp[i]=dp[maxi]+1;
ans=max(ans,dp[i]);
}
cout << n-ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
652 KB |
Output is correct |
2 |
Correct |
41 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
848 KB |
Output is correct |
2 |
Correct |
50 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
848 KB |
Output is correct |
2 |
Correct |
30 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
896 KB |
Output is correct |
2 |
Correct |
48 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
896 KB |
Output is correct |
2 |
Correct |
50 ms |
944 KB |
Output is correct |