#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ins insert
#define pb push_back
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<
const int mod = 1e9+7 ,
sze= 5000 + 23 ,
inf = INT_MAX ,
L = 31 ;
int dp[sze];
void opt1z(){
int n,k;
cin>>n>>k;
vector<int> arr(n),color(n);
multiset<int> lst;
map<int,vector<int>> idx;
for(int i=0;i<n;i++){
cin>>arr[i];
idx[arr[i]].pb(i);
lst.ins(arr[i]);
}
for(auto &v:idx){
reverse(all(v.second));
}
int c = 1;
int nm = 0;
while(!lst.empty()){
nm++;
if(nm==k+1){
nm=1;
c++;
}
color[idx[*lst.begin()].back()]=c;
idx[*lst.begin()].pop_back();
lst.erase(lst.begin());
}
// for(auto v:color){
// cout<<v<<" ";
// }
// cout<<endl;
int ans=0;
for(int i=0;i<n;i++){
dp[i]=1;
for(int j=0;j<i;j++){
if(color[j]<=color[i]){
dp[i]=max(dp[i],dp[j]+1);
}
}
ans=max(ans,dp[i]);
}
putr(n - ans);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
// cin>>tt;
while(tt--){
opt1z();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1116 KB |
Output is correct |
2 |
Correct |
20 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1112 KB |
Output is correct |
2 |
Correct |
25 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1116 KB |
Output is correct |
2 |
Correct |
11 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1292 KB |
Output is correct |
2 |
Correct |
23 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
1116 KB |
Output is correct |
2 |
Correct |
25 ms |
1116 KB |
Output is correct |