AcWing 1227. 分巧克力
原题链接
简单
作者:
不知名的fE
,
2024-11-21 18:44:55
,
所有人可见
,
阅读 1
和机器人跳跃问题(找的是左端点)是一样的,二分找右端点即可
import java.util.*;
public class Main {
static final int N = 100010;
static int[] h = new int[N], w = new int[N];
static int n, m;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split(" ");
n = Integer.parseInt(s[0]); m = Integer.parseInt(s[1]);
for (int i = 0; i < n; i++) {
String[] str = sc.nextLine().split(" ");
h[i] = Integer.parseInt(str[0]);
w[i] = Integer.parseInt(str[1]);
}
int l = 1, r = 100000;
while (l < r) {
int mid = l + r + 1 >> 1;
if (cheek(mid)) l = mid;
else r = mid - 1;
}
System.out.println(l);
}
static boolean cheek(int u) {
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt += (h[i] / u) * (w[i] / u);
if (cnt >= m) return true;
}
return false;
}
}