2,4,5,6,7,8全部re为什么

P2440 木材加工

yanshuai666 @ 2024-12-22 22:24:11

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k, maxx = 0, ans = 0, num = 0;
int q[N];
bool check(int x)
{
    num = 0;
    for (int i = 0; i < n; i++)
        num += q[i] / x;
    if (num == k)
        return 1;
    return 0;
}
int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
        if (q[i] > maxx)
            maxx = q[i];
    }
    int l = 0, r = maxx;
    while (l <= r)
    {
        int mid = l + r >> 1;
        if (check(mid))
        {
            l = mid + 1;
            ans = mid;
        }
        else
            r = mid - 1;
    }
    if (ans < 1)
        cout << "0";
    cout << ans;

    return 0;
}

|