solution.cpp 675 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <stdio.h>
#include <string.h>
int co[100100][2];

int coun(int n, int x)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += (co[i][0] / x) * (co[i][1] / x);
    }
    return sum;
}

int binary(int n, int k)
{
    int l = 0, r = 100000;
    while (l < r)
    {
        int mid = (r - l) / 2 + l;
        if (coun(n, mid) > k)
            r = mid - 1;
        else if (coun(n, mid) < k)
            l = mid + 1;
        else
            return mid;
    }
    return r;
}

int main()
{
    int n;
    int k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d%d", &co[i][0], &co[i][1]);
    printf("%d\n", binary(n, k));
}