P2440 木材加工
程序员文章站
2022-03-11 08:34:10
https://www.luogu.com.cn/problem/P2440#include#include#include#include#includeusing namespace std;const int maxn=1e5+10;typedef long long LL;LL a[maxn];LL n,k;LL check(...
https://www.luogu.com.cn/problem/P2440
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
LL a[maxn];
LL n,k;
LL check(LL mid)
{
LL sum=0;
for(LL i=1;i<=n;i++)
{
sum+=a[i]/mid;
}
if(sum>=k) return 1;
else return 0;
}
LL bsearch(LL l,LL r)
{
while(l<r)
{
LL mid=(l+r+1)>>1;
if(check(mid)) l=mid;
else r=mid-1;
}
return l;
}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
cin>>n>>k;
for(LL i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+1+n);
LL t=bsearch(0,a[n]);
if(t==0)
{
cout<<"0"<<endl;
}
else cout<<t<<endl;
return 0;
}
本文地址:https://blog.csdn.net/zstuyyyyccccbbbb/article/details/107188049
上一篇: Django forms 主要的标签介绍
下一篇: axios取消上次重复请求