#include<bits/stdc++.h>
using namespace std;
#define Study ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define fori for(ll i=0;i<n;i++)
#define ins insert
void work(){
ll n,k;
cin>>n>>k;
vector<ll>a(n+1);
vector<ll>ca(n+1);
vector<ll>dpq(n+1,0),dpa(n+1,0);
map<ll,ll>m;
for(ll i=1;i<=n;i++){
cin>>a[i];
ca[i]=a[i];
}
sort(a.begin(),a.end());
for(ll i=1;i<=n;i++){
ll ans=i/k;
if(i%k!=0)
ans++;
m[a[i]]=ans;
}
ll maximumgroup=m[ca[1]];
for(ll i=2;i<=n;i++){
dpq[i]=dpq[i-1];
if(m[ca[i]]>maximumgroup){
maximumgroup=m[ca[i]];
}
else if(m[ca[i]]<maximumgroup){
dpq[i]++;
}
}
maximumgroup=m[ca[n]];
for(ll i=n-1;i>=1;i--){
dpa[i]=dpa[i+1];
if(m[ca[i]]<maximumgroup){
maximumgroup=m[ca[i]];
}
else if(m[ca[i]]>maximumgroup){
dpa[i]++;
}
}
cout<<min(dpa[1],dpq[n]);
}
int main(){
Study;
ll t=1;
//cin>>t;
while(t--){
work();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |