首页 > 其他分享 >1227. 分巧克力

1227. 分巧克力

时间:2022-09-07 10:35:14浏览次数:112  
标签:1227 巧克力 int res mid 1e5 include

https://www.acwing.com/problem/content/1229/

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int n, k;
const int N = 1e5 + 10;
int h[N], w[N];
bool check(int mid)
{
	int res = 0;
	for (int i = 0; i < n; i++)
	{
		res += (h[i] / mid) * (w[i] / mid);
		if (res >= k)return 1;
	}
	return 0;
}
int main()
{
	cin >> 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 = r + l + 1 >> 1;
		if (check(mid))l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}

标签:1227,巧克力,int,res,mid,1e5,include
From: https://www.cnblogs.com/lxl-233/p/16664416.html

相关文章