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 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个物品,一人如果选择一种物品就必须连续吃这一类物品。
开一个数组,记录每一个种类的数量,暴力即可。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
using namespace std;
const double eps = 1e-8;
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e5 + 10;
const int MAXT = 10000 + 10;
#define N 10005
int n,m;
int a[155];
int vis[155];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
vis[a[i]]++;
}
sort(vis+1,vis+100+1,cmp);
int ans=0;
for(int i=1;i<=100;i++) //枚举活下来天数
{
int sum=0;
for(int j=1;j<=n;j++) //枚举物品种类数量,枚举前n个就行
{
sum+=(vis[j]/i); //满足的人数
}
if(sum>=n)
ans=i;
else
break;
}
printf("%d\n",ans);
}
return 0;
}
标签:const,Expedition,int,42,1011B,CodeForces,food,include,type From: https://blog.51cto.com/u_14932227/6041960