二分 验证答案
#include
#include <string.h>
#include
#include <stdio.h>
#include

using namespace std;

typedef long long ll;
ll hi[100010];
ll wi[100010];
int n;
ll k;
bool isok(ll ans)
{
ll sum = 0;
for(int i = 0 ; i < n ; i++)
{
sum +=(hi[i] / ans) * (wi[i] / ans);
if(sum >=k)
return true;
}
return false;
}
int main()
{
cin>>n>>k;
for(int i = 0 ; i < n ; i++)
{
cin>>hi[i]>>wi[i];
}
ll l = 1,r = 100000,ans;
while(l <=r)
{
ans = (l + r) / 2;
if(isok(ans)) l = ans + 1;
else r = ans -1;
}
l++;

while(l--)  //目的是验证ans是进行计算而出的答案  而不是无法找出答案的终止值 
{
	
	if(isok(l))  break;
}
cout<<ans<<" "<<l<<endl;

}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-12-10
  • 2021-07-25
  • 2022-02-06
  • 2021-07-18
  • 2021-10-22
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2021-06-24
相关资源
相似解决方案