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斤食物,每个人只能吃一种食物,而且每天必须吃一斤食物,问n个人最多能活几天。

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

 #include<stdio.h>
#include<string.h>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int MAXN=3e5+;
map<int,int>::iterator it;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
map<int,int >mp;
int i,siz,n,rt,m,g=,flag=,ck=;
int ans[MAXN]= {};
int t[MAXN]= {};
int s[MAXN]= {};
scanf("%d%d",&n,&m);
for(i=; i<m; i++)
{
scanf("%d",&rt);
mp[rt]++;
}
int r=n-mp.size();
for(it=mp.begin(); it!=mp.end(); it++)
{
s[g++]=it->second;
}
sort(s,s+g,cmp);
for(i=; i<g; i++)
{
if(i==n)
break;
ans[ck++]=s[i];
}
for(; ck<n; ck++)
ans[ck]=; for(i=; i<n; i++)
t[i]=ans[i];
for(i=; i<=; i++)
{
for(int j=; j<n; j++)
{
if(ans[j]-i<)
{
int k,cur=ans[j]-i;
for(k=; k<n; k++)
{
int kk=ans[k]-i;
if(kk>=i)
{
ans[k]-=i;
ans[j]=;
break;
}
}
if(k==n)
{
flag=;
break;
}
} }
if(flag==)
break;
for(int i=; i<n; i++)
ans[i]=t[i]; } printf("%d\n",i-); return ;
}

当然这道题也可以二分查找

 #include<stdio.h>
#include<string.h>
#include<stack>
#include<string.h>
#include<queue>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
const int MAXN=3e5+;
int m,n,l,flag;
int str[MAXN];
map<int,int>::iterator it;
int solve(int mid)
{
int ans=;
for(int i=;i<l;i++)
{
ans+=str[i]/mid;
}
if(ans>=m)
flag=;
if(ans>=m)
return ;
return ;
}
int main()
{
cin>>m>>n;
int k;
map<int,int>mp;
for(int i=;i<n;i++)
{
cin>>k;
mp[k]++;
}
for(it=mp.begin();it!=mp.end();it++)
{
str[l++]=it->second;
}
int left=,right=,mid;
while(left<=right)
{
mid=(left+right)/;
if(solve(mid))
{
left=mid+;
}
else
{
right=mid-;
}
}
if(!flag)
right=;
cout<<right<<endl;
return ;
}

最新文章

  1. WM8978和VS1053B的区别
  2. django 的模板语言
  3. Linux下配置OpenCV1.0环境
  4. maven+Jenkins学习小记
  5. memcached 介绍
  6. Bootstrap新手学习笔记——css
  7. FTP常用故障代码注解
  8. UNIX,基础知识,文件IO,文件和目录
  9. MVC+EF 随笔小计————Html Helpers
  10. js兼容各个浏览器的复制功能
  11. rsync是类unix系统下的数据镜像备份工具
  12. Qemu之Network Device全虚拟方案三: I/O虚拟化
  13. UNIX系统接口
  14. Mysql主从复制(基于Log)
  15. (4.7)mysql备份还原——深入解析二进制日志(3)binlog的三种日志记录模式详解
  16. Vue + webpack 项目配置化、接口请求统一管理
  17. nginx 学习笔记(5) nginx调试日志
  18. webpack4.5.0+vue2.5.16+vue-loader 实战组件化开发案例以及版本问题中踩的一些大坑!!!
  19. HTML语义化(2016/3/16更新)
  20. 使用BasicDataSource引发的数据库连接中断的问题和解决方法

热门文章

  1. Win7 x64安装Paramiko
  2. ElasticSearch安装及简单配置说明
  3. 2017.10.26 ECN + product spec+ cypress ble module test+
  4. MySqlDBHelper数据库连接
  5. git合并分支与解决冲突
  6. maven install时自动施行单元测试
  7. 5,基于关系和超链接的 API
  8. JAVA如何以追加的方式向文件中写入信息?
  9. SP104 HIGH - Highways
  10. 处理mysql主从中断