AcWing 1227. 分巧克力(二分)
和剪绳子基本一样
680.剪绳子 (二分)
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N][2];
int n, m;
bool check(int len) {
int cnt = 0;
for (int i = 0; i < n; i++) {
int c1 = a[i][0] / len, c2 = a[i][1] / len;
cnt += c1 * c2;
}
return cnt <= m;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)cin >> a[i][0] >> a[i][1];
int l = 1, r = 1e5;
while (l < r) {
int m = (l + r + 1) / 2;
if (check(m))r = m-1;
else l=m;
}
cout << l << endl;
return 0;
}
网友评论