#include<iostream>
#include<cstring>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int N = 0,
K = 0;
bool check(int side,vector<pair<int,int>>& list)
{
int cnt = 0;
for(int i = 0 ; i < list.size();i ++)
{
cnt += ((list[i].first / side) * (list[i].second / side));
if(cnt >= K)
{
return true;
}
}
return false;
}
int BinarySearchAns(vector<pair<int,int>>& list,int left,int right)
{
while(left + 1 < right)
{
int mid = (left + right) >> 1;
if(check(mid,list))
{
left = mid;
}
else
{
right = mid;
}
}
return left;
}
int main(void)
{
vector<pair<int,int>> list;
scanf("%d%d",&N,&K);
int maxLen = -1;
for(int i = 0 ; i < N ; i ++)
{
int h = 0,
w = 0;
scanf("%d%d",&h,&w);
maxLen = max(maxLen,h);
maxLen = max(maxLen,w);
list.push_back({h,w});
}
int ans = BinarySearchAns(list,1,maxLen);
printf("%d",ans);
return 0;
}
疑问如题