题目来源:http://codeforces.com/contest/1011/problem/B
B. Planning The Expedition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 (1≤n≤1001≤n≤100, 1≤m≤1001≤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 (1≤ai≤1001≤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 11to 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个食物;食物的不同类型a[i],每一个人在吃了一种食物之后只能继续吃这种食物,不能够去吃其他食物。
问:n个人最多可以存活多少天。
题解:在这个题中,我们可以从1天开始跑 看他是否能够使得n个人存活。那么,可以用二分搜索来做
代码:
#include<map>
#include<stack>
#include<bitset>
#include<math.h>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define close ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
const int MAX_N=1100+50;
const int INF=0x3f3f3f3f;
ll mod = 1e9+7;
int n,m;
int a[MAX_N];
bool check(int b)
{
int r = 0;
for(int i = 0; i < MAX_N; i++)
r += a[i] / b;
return r >= n;
}
int main()
{
cin>>n>>m;
int x;
for(int i = 0; i < m; i++)
{
cin>>x;
a[x]++;
}
int ans = 1;
while(check(ans))
ans++;
cout << ans - 1 << endl;
return 0;
}