6 solutions

  • 0
    @ 2022-5-7 20:45:27
    #include<iostream>
    
    using namespace std;
    typedef long long LL;
    const int N=1e8+10;
    int n,k;
    LL a[N];
    bool check(int x){
    	int m=0;
    	for(int i=0;i<n;i++){
    		m+=a[i]/x;//a[i]/x表示的是当前木棍能切出的长度为x的块数,把所有木棍的对应值加起来就是当前x的最大切出来的块数 
    	}
    	if(m>=k){
    			return true;
    	}
    	return false;
    }
    int main()
    {
    	cin>>n>>k;
    	for(int i=0;i<n;i++) cin>>a[i];
    	int l=0,r=N;
    	while(l<r){
    		int mid=(l+r+1)/2;
    		if(check(mid)) l=mid;//如果当前的最大值满足大于等于k,说明l还有可能更大,所以往右边找 
    		else r=mid-1;
    	}
    	cout<<l<<endl;
    	return 0;
    }
     
     
    

    Information

    ID
    281
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    # Submissions
    131
    Accepted
    65
    Uploaded By