Files
python/TangDou/LanQiaoBei/LanQiaoBei13ShengSai_ZJ_I/BC4_ErFen.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

51 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int INF = 0x3f3f3f3f;
int n, k;
int w[N], h[N];
int tmax = -INF;
/*
2 6
4 3
5 4
答案:
2
*/
// 检查x是否满足某种性质
bool check(int x) {
int cnt = 0;
for (int j = 1; j <= n; j++)
cnt += (w[j] / x) * (h[j] / x);
//以2为例,cnt=6 k=6 正合适
//以1为例 cnt=32 k=6 cnt>k
//所以最终的限制条件为cnt<=k
return cnt <= k;
}
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> h[i];
tmax = max(min(w[i], h[i]), tmax);
}
//二分查询
int l = 1, r = tmax;
while (l < r) {
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid + 1;
}
//也可能找不到答案
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += (w[i] / l) * (h[i] / l);
if (cnt < k)
cout << -1 << endl;
else
cout << l << endl;
return 0;
}