CodeForces 5891 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.

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.


  水题    题目大意:一种球的颜色表示一个表示参与者  为公平起见  球的每种颜色的数量应该相等  现在给出每种颜色

的球的数量  问至少要给多少个球重新刷颜色才能使每种颜色的球数量相等



AC代码:

#include <stdio.h>  
  
int main(){  
    int n,k;  
    int x;  
    int a[110];  
    int average;  
    int count=0;  
      
    scanf ("%d%d",&n,&k);  
      
    average=n/k;  
      
    for (int i=1;i<=k;i++){  
        a[i]=0;  
    }  
      
    for (int i=0;i<n;i++){  
        scanf ("%d",&x);  
        a[x]++;  
    }  
      
    for (int i=1;i<=k;i++){  
        if (a[i]>average){  
            count+=(a[i]-average);  
        }  
          
    }  
      
    printf ("%d\n",count);  
      
    return 0;  
}   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值