【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest I】【水题】Lottery 均分气球最小修改数

I. Lottery
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 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 test(s)
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.



#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=105,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n,k,x;
int a[N];
int main()
{
	while(~scanf("%d%d",&n,&k))
	{
		MS(a,0);
		int ave=n/k;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			++a[x];
		}
		int ans=0;
		for(int i=1;i<=k;i++)ans+=abs(a[i]-ave);
		printf("%d\n",ans>>1);
	}
	return 0;
}
/*
【题意】
有k个人,n个球。(1<=k<=n<=100,且n是k的倍数)
每个球初始都有一个所属者,最后我们想使得每个人都拥有相同数量的球。
问你最少的对求所属者的修改量是多少。

【类型】
水题

【分析】
直接求(∑abs(每个人拥有球量-ave))/2即可

*/


你可能感兴趣的:(ACM,ICPC,水题,codeforces)