Codeforces Round #499 (Div. 2)(1011)

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.

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

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.

题意:有n个人去火星,有m斤食物,每个人只能吃一种食物,而且每天必须吃一斤食物,问n个人最多能活几天。

题解:由于数据量比较小,完全可以用暴力解决,一年一年往上加,不满足条件则找到最优解。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stack>
 4 #include<string.h>
 5 #include<queue>
 6 #include<algorithm>
 7 #include<iostream>
 8 #include<map>
 9 #include<vector>
10 #define PI acos(-1.0)
11 using namespace std;
12 typedef long long ll;
13 const int MAXN=3e5+10;
14 map<int,int>::iterator it;
15 bool  cmp(int a,int b)
16 {
17     return a>b;
18 }
19 int main()
20 {
21     map<int,int >mp;
22     int i,siz,n,rt,m,g=0,flag=0,ck=0;
23     int ans[MAXN]= {0};
24     int t[MAXN]= {0};
25     int s[MAXN]= {0};
26     scanf("%d%d",&n,&m);
27     for(i=0; i<m; i++)
28     {
29         scanf("%d",&rt);
30         mp[rt]++;
31     }
32     int r=n-mp.size();
33     for(it=mp.begin(); it!=mp.end(); it++)
34     {
35         s[g++]=it->second;
36     }
37     sort(s,s+g,cmp);
38     for(i=0; i<g; i++)
39     {
40         if(i==n)
41             break;
42         ans[ck++]=s[i];
43     }
44     for(; ck<n; ck++)
45         ans[ck]=0;
46 
47     for(i=0; i<n; i++)
48         t[i]=ans[i];
49     for(i=1; i<=100; i++)
50     {
51         for(int j=0; j<n; j++)
52         {
53             if(ans[j]-i<0)
54             {
55                 int k,cur=ans[j]-i;
56                 for(k=0; k<n; k++)
57                 {
58                     int kk=ans[k]-i;
59                     if(kk>=i)
60                     {
61                         ans[k]-=i;
62                         ans[j]=0;
63                         break;
64                     }
65                 }
66                 if(k==n)
67                 {
68                     flag=1;
69                     break;
70                 }
71             }
72 
73         }
74         if(flag==1)
75             break;
76         for(int i=0; i<n; i++)
77             ans[i]=t[i];
78 
79     }
80 
81     printf("%d\n",i-1);
82 
83 
84     return 0;
85 }

猜你喜欢

转载自www.cnblogs.com/moomcake/p/9425419.html