求调--必关

P2440 木材加工

wawatime1 @ 2024-10-08 17:44:32


#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100001];
int calc (int x){
    int s = 0;
    for (int i = 1; i <= n; i++)
        s += a[i] / x;
    if (s >= k)
        return 1;
    return 0;
}
int t;
int m;
int ans;
int main (){
    scanf ("%d%d", &n, &k);
    for (int i = 1; i <= n; i++){
        scanf ("%d", &a[i]);
        t += a[i];
        m = max(m, a[i]);
    }
    if (t < k){
        printf ("0");
        return 0;
    }
    int l = 1, r = t;
    while (l <= r){
        int mid = (l + r) / 2;
        if (calc(mid)){
            l = mid + 1;
            ans = mid;
        }
        else
            r = mid - 1;
    }
    printf ("%d", ans);
    return 0;
}

by lichenxi111 @ 2024-10-08 17:50:09

@wawatime1 十年OI一场空,不开long long见祖宗


by OIer_bcx_ @ 2024-10-08 17:51:41

@wawatime1 十年OI一场空,____


by wawatime1 @ 2024-10-08 17:55:17

谢谢大佬指教,已关


by Hsl_Beat @ 2024-10-25 16:29:30

daimayuan来的


|