P2440 木材加工

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章