↓ 跳过正文
  1. Posts/

codeforces 589 I - Lottery(水)

·520 字·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}

相关文章

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

·503 字·2 分钟
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.

codeforces #322 div 2 A. Vasya the Hipster(纱布题)

·471 字·1 分钟
A. Vasya the Hipster time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

uva 489

·711 字·2 分钟
In ``Hangman Judge,’’ you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:

poj 2159 Ancient Cipher(水)

·348 字·1 分钟
由于顺序是可以改变的. 所以考虑是否可以映射.只要存在字母对应出现的次数都相同.那么就可以通过映射得到. 具体是开一个数组记录每个字母出现的次数… 然后sort

codeforces #317 div2 A. Arrays (水)

·206 字·1 分钟
应该3分钟过的题。。。 结果花了8分钟。。。ssssad 代码实现 1/************************************************************************* 2 > File Name: code/cf/#317/A.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月23日 星期日 00时29分47秒 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#define y1 hust111qqz 22#define yn hez111qqz 23#define j1 cute111qqz 24#define ms(a,x) memset(a,x,sizeof(a)) 25#define lr dying111qqz 26using namespace std; 27#define For(i, n) for (int i=0;i<int(n);++i) 28typedef long long LL; 29typedef double DB; 30const int inf = 0x3f3f3f3f; 31const int N=1E5+7; 32int na,nb,k,m; 33int a[N],b[N]; 34int main() 35{ 36 #ifndef ONLINE_JUDGE 37 freopen("in.txt","r",stdin); 38 #endif 39 cin>>na>>nb; 40 cin>>k>>m; 41 for ( int i = 1 ; i <= na ; i++){ 42 scanf("%d",&a[i]); 43 } 44 for ( int i = 1 ; i<= nb ; i++){ 45 scanf("%d",&b[i]); 46 } 47 if (a[k]<b[nb-m+1]){ 48 puts("YES"); 49 } 50 else 51 { 52 puts("NO"); 53 } 54 55 56 #ifndef ONLINE_JUDGE 57 fclose(stdin); 58 #endif 59 return 0; 60}