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 ;
}

Codeforces Round #499 (Div. 2)(1011)的更多相关文章

  1. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  2. Codeforces Round #219 (Div. 1)(完全)

    戳我看题目 A:给你n个数,要求尽可能多的找出匹配,如果两个数匹配,则ai*2 <= aj 排序,从中间切断,分成相等的两半后,对于较大的那一半,从大到小遍历,对于每个数在左边那组找到最大的满足 ...

  3. Codeforces Round #249 (Div. 2) (模拟)

    C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #544 (Div. 3) (补)

    D:没有注意到a==0&&b==0的情况,把自己卡崩了.对于数学公式推导一定要注意关于0的特殊情况,不可以少 #include <iostream> #include &l ...

  5. Codeforces Round #613 (Div. 2) (A-E)

    A略 直接求和最大的子序列即可(注意不能全部选中整个子序列) or #include<bits/stdc++.h> using namespace std; void solve(){ i ...

  6. C. Queen Codeforces Round #549 (Div. 2) (搜索)

    ---恢复内容开始--- You are given a rooted tree with vertices numerated from 11 to nn . A tree is a connect ...

  7. Codeforces Round #612 (Div. 2) (A-D)

    直 接看所有A后面连续P的个数最大值 #include<cstring> #include<cstdio> #include<set> #include<io ...

  8. Codeforces Round #499 (Div. 1)部分题解(B,C,D)

    Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...

  9. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

随机推荐

  1. HDU 3452 Bonsai(树形dp)

    Bonsai Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  2. ASP.NET学习路线图(转)

    如果你已经有较多的面向对象开发经验,跳过以下这两步: 第一步 掌握一门.NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET. ASP.NE ...

  3. docker中宿主机与容器(container)互相拷贝传递文件的方法

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/71425077 本文出自[我是干勾鱼的博客] 前面讲解过如何进入.退出docker ...

  4. 迭代器模式在 Java 容器中的实现

    迭代器接口是迭代器模式实现的精髓: public interface Iterator<E> { boolean hasNext(); E next(); ... } 假设某容器名为 Xx ...

  5. SSH框架(2)

    个人分类: Java面试   Struts 谈谈你对Struts的理解. 答: 1.struts是一个按MVC模式设计的Web层框架,其实它就是一个大大的servlet,这个Servlet名为Acti ...

  6. sublime text 3设置浏览器快捷键

    一.设置默认浏览器 1,打开sublime 依次选择 tools > build system > new build system... 2,选择你喜欢的浏览器,右键 > 属性 把 ...

  7. fn project 运行时配置选项

    Env Variables Description Default values DB_URL The database URL to use in URL format. SeeDatabases  ...

  8. Ubuntu的复制粘贴操作及常用快捷键(摘自网络)

    Ubuntu的复制粘贴操作 终端最大化快捷键:crtl + win + 上 1.最为简单,最为常用的应该是鼠标右键操作了,可以选中文件,字符等,右键鼠标,复制,到目的地右键鼠标,粘贴就结束了. 2.快 ...

  9. Toolbar使用

    原文地址 http://www.cnblogs.com/Dentist/p/4370176.html Android4.0出现的Actionbar提供了同意方便的导航管理.很大程度的统一了Androi ...

  10. 30G 的redis 如何优化

    突然发现我们的redis 已经用了30G了,好吧这是个很尴尬的数字因为我们的缓存机器的内存目前是32G的,内存已经告竭.幸好上上周公司采购了90G的机器,现在已经零时迁移到其中的一台机器上了.(跑题下 ...