TainityAnle
2025-01-10 09:38:37
先按
二分斜率
得到的答案就是斜率大于
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,k,l,r,b[N],c[N];
struct point{
int x,y;
}a[N];
struct node{
int t[N];
void clear(){
memset(t,0,sizeof t);
}
void add(int x,int y){
for(int i=x;i<=n;i+=(i&(-i))) t[i]+=y;
}
int qry(int x){
int res=0;
for(int i=x;i;i-=(i&(-i))) res+=t[i];
return res;
}
}A;
bool cmp(point a,point b){
if(a.x==b.x) return a.y>b.y;
return a.x<b.x;
}
int check(int p){
A.clear();
for(int i=1;i<=n;i++) b[i]=a[i].y-p*a[i].x,c[i]=b[i];
sort(c+1,c+n+1);
int m=unique(c+1,c+n+1)-c-1;
for(int i=1;i<=n;i++) b[i]=lower_bound(c+1,c+m+1,b[i])-c;
int cnt=0;
for(int i=1;i<=n;i++){
cnt+=A.qry(b[i]);
A.add(b[i],1);
}
return cnt;
}
signed main(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
sort(a+1,a+n+1,cmp);
l=-1000000000,r=1000000000;
while(l<r){
int mid=(l+r+1)/2;
int tmp=check(mid);
if(tmp<k) r=mid-1;
else l=mid;
}
cout<<l;
return 0;
}