欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

P2440 木材加工

程序员文章站 2022-06-15 12:38: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