题目: https://www.51nod.com/Challenge/Problem.html#!#problemId=1105
思路:先二分答案,然后枚举一个数组,再二分另一个数组,非常典型的二分里面套二分
#include<bits/stdc++.h> using namespace std; ll a[500003]; ll b[500003]; int n,m; int che(ll c) { int sum=0; for(int i=n; i; i--) { ll z=c/a[i]; if(c%a[i])z++; sum+=n-(lower_bound(b+1,b+1+n,z)-b-1); } return sum>=m; } int main() { //ios::sync_with_stdio(false); cin>>n>>m; for(int i=1; i<=n; i++) sll(a[i],b[i]); sort(a+1,a+1+n); sort(b+1,b+1+n); ll l,r; l=a[1]*b[1]; r=a[n]*b[n]; ll qq=0; while(l<=r) { ll mid=(l+r)>>1; if(che(mid))qq=mid,l=mid+1; else r=mid-1; } cout<<qq<<endl; }