AcWing 1227. 分巧克力
原题链接
简单
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
int n, k;
int h[N], w[N];
//判断x长度是否可行
bool check(int x){
LL sum = 0;
for(int i = 0; i < n; i++){
sum += (LL)(h[i] / x) * (w[i] / x);
}
if(sum >= k) return true;
else return false;
}
int main(){
scanf("%d%d", &n, &k);
for(int i = 0; i < n; i++) scanf("%d%d", &h[i], &w[i]);
int l = 1, r = 1e5;
while(l < r){
int mid = l + r + 1 >> 1;
if(check(mid)){
l = mid;
}else{
r = mid - 1;
}
}
cout << l << endl;
return 0;
}