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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define ROF(i, a, b) for (int i = b; i >= a; --i)
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef double DB; typedef pair<ll,ll> pll; typedef array<ll,3> arr; const ll MAXN=static_cast<ll>(1e5)+10; const DB eps=1e-7; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; }
ll N,K,tr[MAXN]; DB curP[MAXN];
struct posv{ int p,v;
}; posv pv[MAXN]; inline bool cmp(posv a, posv b){ return a.p<b.p; }
inline ll lowbit(ll x){ return x&(-x); } inline void add(ll x) { while (x<=N) { tr[x]+=1; x+=lowbit(x); } } inline ll query(ll x){ ll res=0; while (x>0) { res+=tr[x]; x-=lowbit(x); } return res; } inline bool check(DB t){ vector<DB> li(N);
FOR(i, 1, N){ curP[i]=pv[i].p*1.0+t*pv[i].v; li[i-1]=curP[i]; } sort(li.begin(), li.end()); vector<DB>::iterator it=unique(li.begin(), li.end()); li.resize(it-li.begin()); FOR(i, 1, N){ tr[i]=0;
} ll res=0; FOR(i, 1, N){ ll rk=lower_bound(li.begin(), li.end(),curP[i])-li.begin()+1; res+=max(i-1-query(rk-1),0ll); add(rk); } if(res>=K){ return true; } return false; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
N=read(),K=read(); FOR(i, 1, N){ pv[i].p=read(); pv[i].v=read();
} sort(&pv[1], &pv[N+1],cmp); DB l=0,r=1e9; while (r-l>(eps*l)) { DB mid=(l+r)/2.0; if(check(mid)){ r=mid; }else{ l=mid; } } if(fabs(l-1e9)<(eps*l)){ cout<<"No\n"; return 0; } cout<<"Yes\n"; cout<<setprecision(7)<<fixed<<l<<endl; return 0; }
|