Lottery
Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 589I
Description
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
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
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 kcolors.
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.
Sample Input
Input
4 2 2 1 2 2
Output
1
Input
8 4 1 2 1 1 1 4 1 4
Output
3
Hint
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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[110];
int main()
{
int n,m,mm,i,j,k;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(a,0,sizeof(a));
mm=n/m;
for(i=1;i<=n;i++)
{
scanf("%d",&k);
a[k]++;
}
int sum=0;
for(i=1;i<=m;i++)
{
if(a[i]<mm)
{
sum+=mm-a[i];
}
}
printf("%d\n",sum);
}
return 0;
}