package lanqiaobei;
import java.util.Scanner;
import static java.lang.Integer.max;//导入的包 重要
public class try1 {
static int n,k;
static int h[]=new int[100005];
static int w[]=new int[100005];
static boolean pd(int l) {
int sum=0;
for(int i=0;i<n;i++) {
sum+=(h[i]/l)*(w[i]/l);//用于表示可以掰成几个巧克力
if(sum>=k) {
return true;
}
}
return false;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
k=sc.nextInt();
int high=0;
for(int i=1;i<=n;i++) {
h[i]=sc.nextInt();//利用数组保存
w[i]=sc.nextInt();
high=max(high,h[i]);//从1开始因为都是正方形所以两个挑个大的开始算
high=max(high,w[i]);
}
int low=1;
int mid=0;
while(low<high) {
mid=(low+high+1)/2;
if(pd(mid))
low=mid;
else
high=mid-1;//选择小的那个(其实都一样)
}
System.out.println(low);
}
}
分巧克力 二分(临时抱佛脚)
于 2024-04-12 19:19:48 首次发布