P2440 木材加工

点击查看代码
#include<bits/stdc++.h>
using namespace std;

const int N=1e5+10;
int n;
long long k;
long long L[N];

bool check(int x)
{
    long long cnt=0;
    for(int i=0;i<n;i++){
        cnt+=L[i]/x;
    }

    return cnt>=k;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);

    cin>>n>>k;
    long long max_l=0;
    for(int i=0;i<n;i++){
        cin>>L[i];
        max_l=max(max_l,L[i]);
    }

    int l=1,r=max_l;
    int ans=0;

    while(l<=r){
        int mid=l+(r-l)/2;
        if(check(mid)){
            ans=mid;
            l=mid+1;
        }else{
            r=mid-1;
        }
    }

    cout<<ans<<endl;

    
}
posted @ 2026-01-26 23:28  AnoSky  阅读(0)  评论(0)    收藏  举报