I. Lottery

来源:互联网 发布:kik是什么软件 编辑:程序博客网 时间:2024/04/18 18:34

time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, 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 cimeans 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.

Sample test(s)
input
4 22 1 2 2
output
1
input
8 41 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.



解题说明:此题要求每个人中奖的概率一样,其实就是求平均数,先统计每种颜色球的个数,然后判断与均值差多少,再决定染色的数目。


#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){    int k,n,i,c,ans=0;int a[101],b[103];    scanf("%d %d",&n,&k);    c=n/k;    for(i=1;i<=k;i++)    {b[i]=0;}for(i=0;i<n;i++)    {        scanf("%d",&a[i]);        b[a[i]]++;    }    for(i=1;i<=k;i++)    {        if(b[i]>c)        {            ans+=(b[i]-c);        }    }    printf("%d\n",ans);    return 0;}


0 0