/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 22ms 576.0 KiB
#4 Accepted 30ms 1.539 MiB
#5 Accepted 63ms 3.41 MiB
#6 Accepted 60ms 3.391 MiB
#7 Accepted 39ms 796.0 KiB
#8 Accepted 44ms 824.0 KiB
#9 Accepted 20ms 1.656 MiB
#10 Accepted 24ms 796.0 KiB
#11 Accepted 20ms 916.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e6+10,MOD=1000000007;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
       int n,k;
       cin>>n>>k;
       priority_queue<int>pq;
       map<int,int>mp;
       for(int i=1;i<=n;i++){
         int a;
         cin>>a;
         mp[a]++;
       }
       for(auto it:mp){
        pq.push(it.second);
       }
       vector<int>vis(n+1,0);
       int ans=0;
       for(int i=1;i<=n-k+1;i++){
        if(vis[i])continue;
        int cnt=0;
        for(int j=i;j<=n;j+=k){
            vis[j]=1;
            cnt++;
        }
        int x=pq.top();
        pq.pop();
        int laga=min(x,cnt);
        ans+=(cnt-laga);
        x-=laga;
        if(x>0)pq.push(x);

       }
       cout<<ans<<"\n";

    }
    
   
   return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1062 Roy and Array
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-22 09:40:46
Judged At
2024-05-22 09:40:46
Judged By
Score
100
Total Time
63ms
Peak Memory
3.41 MiB