/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 364.0 KiB
#3 Accepted 36ms 580.0 KiB
#4 Accepted 50ms 1.52 MiB
#5 Accepted 123ms 3.309 MiB
#6 Accepted 125ms 3.301 MiB
#7 Accepted 64ms 620.0 KiB
#8 Accepted 71ms 792.0 KiB
#9 Accepted 32ms 1.574 MiB
#10 Accepted 40ms 584.0 KiB
#11 Accepted 35ms 824.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-12-17 11:30:18
Judged By
Score
100
Total Time
125ms
Peak Memory
3.309 MiB