1079A--Kitchen Utensils

题目

The king’s birthday dinner was attended by k guests. The dinner was quite a success: every person has eaten several dishes (though the number of dishes was the same for every person) and every dish was served alongside with a new set of kitchen utensils.

All types of utensils in the kingdom are numbered from 1 to 100. It is known that every set of utensils is the same and consist of different types of utensils, although every particular type may appear in the set at most once. For example, a valid set of utensils can be composed of one fork, one spoon and one knife.

After the dinner was over and the guests were dismissed, the king wondered what minimum possible number of utensils could be stolen. Unfortunately, the king has forgotten how many dishes have been served for every guest but he knows the list of all the utensils left after the dinner. Your task is to find the minimum possible number of stolen utensils.

Input

The first line contains two integer numbers n and k(1≤n≤100,1≤k≤100) — the number of kitchen utensils remaining after the dinner and the number of guests correspondingly.

The next line contains nn integers a1,a2,…,an (1≤ai≤100) — the types of the utensils remaining. Equal values stand for identical utensils while different values stand for different utensils.

Output

Output a single value — the minimum number of utensils that could be stolen by the guests.

Examples
input
5 2
1 2 2 1 3
output
1
input
10 3
1 3 3 1 3 5 5 5 5 100
output
14
题意:国王邀请k个人来赴宴就餐,每个人都吃了好几道菜(菜的数量对每个人来说都一样),每道菜都配有一套新的厨具。每一套器具都是一样的,由不同类型的器具组成,所有种类的器皿都由1到100编号。每一类器具最多在一道菜只能出现一次。晚餐结束后,客人们都被打发走了,国王想知道能多少餐具被偷。不幸的是,国王忘记了每一位客人有多少菜,但他知道晚餐后剩下的所有餐具的清单。求出丢失餐具的最小数量。
解题思路:首先找出个数最多的餐具种类记为max,当max%k==0时,则表示每个种类餐具数量都应为max(即每个人吃菜数量为max/k道),当max%k!=0时,表示菜的数量大于最多数量餐具的类型,则需要最小该类餐具类型数量为(max/k+1)*k.
AC–Code
import java.util.HashSet;
import java.util.Scanner;

public class CF1079A {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] num = new int[101];
		int n = sc.nextInt();
		int k = sc.nextInt();
		int max = 0;
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i =0;i<n;i++)
		{
			int a = sc.nextInt();
			num[a]++;
			max = Math.max(max, num[a]);
			set.add(a);
		}
		max = max%k==0?max:(max/k+1)*k;
		int c = 0;
		for (Integer integer : set) {
			c += max-num[integer];
		}
		System.out.println(c);
		sc.close();
	}
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值