CodeForces 1011B

本文介绍了一种算法,用于解决给定数量的食物包如何分配给探险队员,使得探险能够持续尽可能多的天数。通过遍历食物种类并利用STL容器map来统计每种食物的数量,进而计算最多可以持续的天数。

Description

Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide food for each participant.

The warehouse has mm daily food packages. Each package has some food type aiai.

Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.

Formally, for each participant jj Natasha should select his food type bjbj and each day jj-th participant will eat one food package of type bjbj. The values bjbj for different participants may be different.

What is the maximum possible number of days the expedition can last, following the requirements above?

Input

The first line contains two integers nn and mm (1n1001≤n≤100, 1m1001≤m≤100) — the number of the expedition participants and the number of the daily food packages available.

The second line contains sequence of integers a1,a2,,ama1,a2,…,am (1ai1001≤ai≤100), where aiai is the type of ii-th food package.

Output

Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.

Sample Input

Input
4 10
1 5 2 1 1 1 2 5 7 2
Output
2
Input
100 1
1
Output
0
Input
2 5
5 4 3 2 1
Output
1
Input
3 9
42 42 42 42 42 42 42 42 42
Output
3

Hint

In the first example, Natasha can assign type 11 food to the first participant, the same type 11 to the second, type 55 to the third and type 22 to the fourth. In this case, the expedition can last for 22 days, since each participant can get two food packages of his food type (there will be used 44 packages of type 11, two packages of type 22 and two packages of type 55).

In the second example, there are 100100 participants and only 11 food package. In this case, the expedition can't last even 11 day.

 

对存活天数进行暴力。

判断该天数能否成立的条件是,对水果的种类数进行暴力,判断所有的水果一共能支持多少人。

注意STL容器map 的使用。

 

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<stack>
 8 #include<deque>
 9 #include<map>
10 #include<iostream>
11 using namespace std;
12 typedef long long  LL;
13 const double pi=acos(-1.0);
14 const double e=exp(1);
15 const int N = 100010;
16 
17 #define lson i << 1,l,m
18 #define rson i << 1 | 1,m + 1,r
19 
20 map<int,int> mp;
21 int main()
22 {
23     int n,m,i,p,j;
24     int x;
25     scanf("%d%d",&n,&m);
26     for(i=1;i<=m;i++)
27     {
28         scanf("%d",&x);
29         mp[x]++;
30     }
31     if(m<n)
32         printf("0\n");
33     else
34     {
35         p=m/n;
36         map<int,int>::iterator it1;
37         for(i=p;i>0;i--)
38         {
39             int sum=0;
40             for(it1=mp.begin();it1!=mp.end();it1++)
41             {
42                 sum+=it1->second/i;
43             }
44             if(sum>=n)
45                 break;
46         }
47         printf("%d\n",i);
48     }
49     return 0;
50 }
View Code

 

转载于:https://www.cnblogs.com/daybreaking/p/9426094.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值