跳过正文
  1. Posts/

codeforces 589 I - Lottery(水)

·2 分钟

I - 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 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 c__i(1 ≤ c__i ≤ k), where c__i 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.

 1/*************************************************************************
 2> File Name: code/hust/20151025/I.cpp
 3> Author: 111qqz
 4> Email: rkz2013@126.com
 5> Created Time: 2015年10月25日 星期日 13时09分42秒
 6************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#include<cctype>
21
22#define yn hez111qqz
23#define j1 cute111qqz
24#define ms(a,x) memset(a,x,sizeof(a))
25using namespace std;
26const int dx4[4]={1,0,0,-1};
27const int dy4[4]={0,-1,1,0};
28typedef long long LL;
29typedef double DB;
30const int inf = 0x3f3f3f3f;
31int n,k;
32int cnt[111];
33
34bool cmp( int a,int b)
35{
36return a>b;
37}
38int main()
39{
40#ifndef  ONLINE_JUDGE
41freopen("in.txt","r",stdin);
42#endif
43
44scanf("%d %d",&n;,&k);
45ms(cnt,0);
46for ( int i = 0 ; i < n ; i++)
47{
48int x;
49scanf("%d",&x);
50cnt[x]++;
51}
52sort(cnt,cnt+105,cmp);
53int ans = 0 ;
54int ave = n/k;
55for ( int i  = 0 ;  i < 105 ; i++)
56{
57if (cnt[i]<=ave) break;
58else ans+=cnt[i]-ave;
59}
60printf("%dn",ans);
61
62
63#ifndef ONLINE_JUDGE
64fclose(stdin);
65#endif
66return 0;
67}

相关文章

POJ 2253 - Frogger (floyd)

·2 分钟
A - Frogger **Time Limit:**1000MS **Memory Limit:**65536KB 64bit IO Format:%I64d & %I64u Submit Status Description Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists’ sunscreen, he wants to avoid swimming and instead reach her by jumping. Unfortunately Fiona’s stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps. To execute a given sequence of jumps, a frog’s jump range obviously must be at least as long as the longest jump occuring in the sequence. The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.

codeforces #326 div 2 A. Duff and Meat(水)

·1 分钟
A. Duff and Meat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly a__i kilograms of meat.

zoj 3635 Cinema in Akiba (树状数组求第K大)

·2 分钟
Cinema in Akiba Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there is only one row so that every audience can enjoy the wonderful movies without any annoyance by other audiences sitting in front of him/her.