当前位置: 移动技术网 > 移动技术>移动开发>IOS > P2440 木材加工

P2440 木材加工

2020年07月08日  | 移动技术网移动技术  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网