1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include<stdio.h> #include<set>
#include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<string.h> #include<queue> #define mem(ss) memset(ss,0,sizeof(ss)) #define rep(d, s, t) for(int d=s;d<=t;d++) #define rev(d, s, t) for(int d=s;d>=t;d--) typedef long long ll; typedef long double ld; typedef double db; #define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int MAXN=50020; ll n,k,a[MAXN],b[MAXN]; inline ll cont(int cur,ll num){ ll t=a[cur],ans=0; int l=1,r=n,mid; while(l<=r){ mid=(l+r)/2; if(t*b[mid]<=num){ l=mid+1; ans=mid; } else{ r=mid-1; } } return ans; } inline bool check(ll x){ ll ans=0; int j=n; for(int i=1;i<=n;i++){ while(a[i]*b[j]>x) j--; ans+=j; } return ans>=k; } int main() {
scanf("%lld%lld",&n,&k); k=n*n-k+1; for(int i=1;i<=n;i++){ scanf("%lld%lld",&a[i],&b[i]); } std::sort(a+1,a+1+n); std::sort(b+1,b+1+n); ll l=a[1]*b[1],r=a[n]*b[n],mid,ans=r; while(l<=r){ mid=(l+r)/2; if(check(mid)){ r=mid-1; ans=mid; } else{ l=mid+1; } } printf("%lld\n",ans); return 0; }
|