codeforces589I

本文介绍了一个基于CodeForces-589I的算法问题,讨论了如何通过最少次数的球颜色重涂,使彩票活动对所有参与者公平。通过分析球的颜色分布,算法计算出使每种颜色球数量相等所需的最小操作数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Lottery

 CodeForces - 589I 

Today Berland holds a lottery with a prize — a huge sum of money! There are kpersons, who attend the lottery. Each of them will receive a unique integer from 1 to k.

The organizers bought n balls to organize the lottery, each of them is painted some color, the colors are numbered from 1 to k. A ball of color c corresponds to the participant with the same number. The organizers will randomly choose one ball — and the winner will be the person whose color will be chosen!

Five hours before the start of the lottery the organizers realized that for the lottery to be fair there must be an equal number of balls of each of k colors. This will ensure that the chances of winning are equal for all the participants.

You have to find the minimum number of balls that you need to repaint to make the lottery fair. A ball can be repainted to any of the k colors.

Input

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 100) — the number of balls and the number of participants. It is guaranteed that n is evenly divisible by k.

The second line of the input contains space-separated sequence of n positive integers ci (1 ≤ ci ≤ k), where ci means the original color of the i-th ball.

Output

In the single line of the output print a single integer — the minimum number of balls to repaint to make number of balls of each color equal.

Examples

Input
4 2
2 1 2 2
Output
1
Input
8 4
1 2 1 1 1 4 1 4
Output
3

Note

In the first example the organizers need to repaint any ball of color 2 to the color 1.

In the second example the organizers need to repaint one ball of color 1 to the color 2 and two balls of the color 1 to the color 3.

 

sol:略水,小学奥数随便搞搞,原题地址已经没了,我也不知道自己写的对不对

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0');    return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=105;
int n,m,Ges[N];
int main()
{
    int i,ans=0;
    R(n); R(m);
    for(i=1;i<=n;i++)
    {
        Ges[read()]++;
    }
    int oo=n/m;
    for(i=1;i<=m;i++) ans+=abs(Ges[i]-oo);
    Wl(ans>>1);
    return 0;
}
/*
Input
4 2
2 1 2 2
Output
1

Input
8 4
1 2 1 1 1 4 1 4
Output
3
*/
View Code

 

转载于:https://www.cnblogs.com/gaojunonly1/p/10738128.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值