/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 1ms 480.0 KiB
#3 Accepted 55ms 572.0 KiB
#4 Accepted 52ms 1.555 MiB
#5 Accepted 115ms 2.293 MiB
#6 Accepted 115ms 2.246 MiB
#7 Accepted 66ms 588.0 KiB
#8 Accepted 73ms 780.0 KiB
#9 Accepted 34ms 1.57 MiB
#10 Accepted 46ms 576.0 KiB
#11 Accepted 34ms 564.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-11-11 03:28:56
Judged By
Score
100
Total Time
115ms
Peak Memory
2.293 MiB