# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140628 | Rouge_Hugo | Studentsko (COCI14_studentsko) | C++14 | 0 ms | 0 KiB |
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;
int n,k;
int a[5005];
int tree[5005*3];
void update (int ind,int st,int end,int uind,int uval)
{
if (st==end)
{
tree[ind]=uval;
return ;
}
int m=(st+end)/2;
if (uind>m)update (ind*2+2,m+1,end,uind,uval);
else update(ind*2+1,st,m,uind,uval);
tree[ind]=max(tree[ind*2+1],tree[ind*2+2]);
}
query(int ind,int st,int end,int uind)
{
if (end<=uind)return tree[ind];
int m=(st+end)/2;
if (uind>m)return max(query(ind*2+1,st,m,uind),query (ind*2+2,m+1,end,uind));
else return query (ind*2+1,st,m,uind);
}
map<int,int>m;
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
m[a[i]]++;
}
int r=0,re=0;
for(auto it:m)
{
re++;
re%=k;
m[it.first]=r;
if (re==0)r++;
}int mx=0;
k=n/k;
r=0;
for(int i=0;i<n;i+=1)
{ r=query(0,0,k-1,m[a[i]]);
// cout<<m[a[i]]<<" ";
mx=max(mx,r+1);
update (0,0,k-1,m[a[i]],r+1);
}
cout<<n-mx;
return 0;
}