Planning The Expedition

Planning The Expedition

Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant.

The warehouse has m daily food packages. Each package has some food type ai.

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 j Natasha should select his food type bj and each day j-th participant will eat one food package of type bj. The values bj 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 n and m (1≤n≤100, 1≤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,…,am (1≤ai≤100), where ai is the type of i-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.

在这里插入图片描述

大意

Natasha 等n个人正计划远征火星,需要为每位参与者提供食物。仓库里有m包食物。第ii包食品的类型是ai。每个参与者每天必须吃一包食物。由于某种原因,每个参与者必须在整个探险过程中吃同种类型的食物,不同的参与者可以吃不同(或相同)类型的食物。当有任意一个参与者没有食物吃的时候,探险结束。

根据上述要求,探险可以持续的最长天数是多少?

思路

由题可得数据范围及其小,m包食物,那么极限情况(一位参与者)可以探险m天,那么探险持续时间 i 的范围便是1~m天。
我们用所有拥有某种食物的数量 a[j] 去除以 i ,即可获得该种食物可以供 a[j]/i 个人生存,累加即可得到可探险 i 天的最大供给食物人数。
我们这时候取 i 的最大值即可获得答案。

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[110]={0};
    for(int i=0;i<m;i++){
        int t;
        cin>>t;
        a[t]++;
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        int cnt=0;
        for(int j=1;j<=100;j++){
            cnt+=a[j]/i;
        }
        if(cnt>=n) ans=max(ans,i);
    }
    cout<<ans<<endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值