AcWing 1227. 分巧克力
原题链接
简单
作者:
fan_22
,
2024-12-01 05:25:58
,
所有人可见
,
阅读 1
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100010;
int n, k;
int h[N], w[N];
int l, r;
int res = 1e9;
int hest = 0;
bool cheak(int x) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum+= (h[i] / x)*(w[i]/x);
}
if (sum >= k)return true;
return false;
}
int binary_search(int l, int r) {
while (l + 1 < r) {
int mid = (l + r) / 2;
if (cheak(mid))l = mid;
else r = mid;
}
if (cheak(l))return l;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> h[i] >> w[i];
hest = max(hest, h[i]);
hest = max(hest, w[i]);
}
l = 0, r = hest + 1;
res=min(binary_search(l,r),res);
cout << res;
return 0;
}