/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 35ms 568.0 KiB
#4 Accepted 50ms 1.367 MiB
#5 Accepted 103ms 3.375 MiB
#6 Accepted 109ms 3.305 MiB
#7 Accepted 61ms 580.0 KiB
#8 Accepted 70ms 824.0 KiB
#9 Accepted 31ms 1.656 MiB
#10 Accepted 38ms 564.0 KiB
#11 Accepted 34ms 952.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-11-11 03:29:54
Judged By
Score
100
Total Time
109ms
Peak Memory
3.375 MiB