求助!!!
查看原帖
求助!!!
273896
L_Hospital_楼主2020/8/25 17:30
# include <iostream>
using namespace std;

int a[100005], n, k;

bool check(int x)
{
    long long cnt = 0;
    for (int i = 1; i <= n; i++)
        cnt += a[i] / x;
    return cnt >= k;
}

int main()
{
    int n, k, maxx = -1;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        maxx = max(maxx, a[i]);
    }
    if (!check(1))
        cout << 0 << endl;
    else
    {
        int small = 1, big = maxx + 1, med = (big + 1) / 2;
        while (big - 1 > small)
        {
            if (!check(med))
                big = med;
            else
                small = med;
            med = (small + big) / 2;
        }
        cout << small << endl;
    }
    return 0;
}
2020/8/25 17:30
加载中...