题解 | 华华给月月准备礼物

华华给月月准备礼物

https://www.nowcoder.com/practice/9963334321e64e61a397b262708e4f65

#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N=2e5+5;

int n,k;
int l[N];

inline int work(int x)
{
    int res=0;
    for(int i=1;i<=n;i++) res+=l[i]/x;
    return res;
}

signed main()
{
    scanf("%lld%lld",&n,&k);
    int maxn=-1;
    for(int i=1;i<=n;i++) scanf("%lld",&l[i]),maxn=max(maxn,l[i]);
    int L=1,R=maxn;
    while(L<=R)
    {
        int mid=(L+R)/2;
        int tmp=work(mid);
        if(tmp<k) R=mid-1;
        else L=mid+1;
    }
    printf("%lld",R);
    return 0;
}

全部评论

相关推荐

牛客42327521...:在你没来公司之前你们公司连登录功能都没做?让一个实习生做登录页面?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务