/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 1ms 488.0 KiB
#3 Accepted 40ms 584.0 KiB
#4 Accepted 42ms 1.309 MiB
#5 Accepted 79ms 2.078 MiB
#6 Accepted 78ms 2.078 MiB
#7 Accepted 59ms 540.0 KiB
#8 Accepted 64ms 784.0 KiB
#9 Accepted 26ms 1.562 MiB
#10 Accepted 39ms 568.0 KiB
#11 Accepted 30ms 540.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int x,k,n; cin>>n>>k;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        m[x]++;
    }
    priority_queue<int>pq;
    for(auto e:m) pq.push(e.second);
    
    int g = n/k;
    int r = n%k;
    int need = g+1;
    int ans = 0;
    for(int i=0;i<r;i++)
    {
        int tp = pq.top();
        pq.pop();
        ans += max(0,need-tp);
        tp = max(0,tp-need);
        if(tp>0) pq.push(tp);
    }
    need = g;
    for(int i=r;i<k;i++)
    {
        int tp = pq.top();
        pq.pop();
        ans += max(0,need-tp);
        tp = max(0,tp-need);
        if(tp>0) pq.push(tp);
    }
    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin>>t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1062 Roy and Array
Language
C++20 (G++ 13.2.0)
Submit At
2024-06-13 15:45:48
Judged At
2024-06-13 15:45:48
Judged By
Score
100
Total Time
79ms
Peak Memory
2.078 MiB