求调(64pts)
  • 板块P2440 木材加工
  • 楼主canwen
  • 当前回复9
  • 已保存回复9
  • 发布时间2024/7/17 17:32
  • 上次更新2024/7/17 19:01:31
查看原帖
求调(64pts)
1284815
canwen楼主2024/7/17 17:32
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(a,b) for(int i=(a);i<=(b);i++)

/*n根木头,k段,求max每段长度*/
int n,k,s[100005],l=0,r,mid,t,ans,pd;

signed main(){
	cin>>n>>k;
	f(1,n){cin>>s[i];pd+=s[i];r=max(s[i],r);};
	if(pd<k) {cout<<"0"<<endl;return 0;}
	while(l<=r){
		mid=(l+r)/2;
		t=0;
		f(1,n) t+=s[i]/mid;
		if(t==k) ans=max(ans,mid);
		if(t>=k) l=mid+1;
		else r=mid-1; 
	}
	
	cout<<ans<<endl;
	
	return 0;
}

WA记录

2024/7/17 17:32
加载中...