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
如对本文有疑问, 点击进行留言回复!!
灰色预测模型GM(1,1)的发展系数a=0或无限接近于0的时候预测的误差以及解决办法
网友评论