Voltage Keepsake
time limit per test 2 second memory limit per test 256 megabytes
You have n devices that you want to use simultaneously.

The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.

You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.

You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.

If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.

传送门:CF801C

Input

The first line contains two integers, n and p (1≤n≤100000, 1≤p≤109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1≤ai,bi≤100000) — the power of the device and the amount of power stored in the device in the beginning.

Output

If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10-4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if .

Sample Input

1
2
3
2 1
2 2
2 1000

Sample Output

1
2.0000000000

题解

二分题 我已经能够在比赛中做出来了 可是今天的这道对Java有毒,所有Java提交都被卡精度了 = = 注意二分的上限应该大于1e10,因为如果不是无限的话,最大时间可以达到10^5*10^5 二分检查的条件就是当前时间所有消耗的是否小于补充的和原来就有的
## AC code:(不包含输入类)
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
import java.io.*;  
import java.util.*;
public class Main {
static double eps=1e-6;
static int[]cost;
static int[]sto;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
int p=sc.nextInt();
cost=new int[n];
sto=new int[n];
long sum=0;
for(int i=0;i<n;i++){
cost[i]=sc.nextInt();
sto[i]=sc.nextInt();
sum+=cost[i];
}
if(sum<=p){
pw.println(-1);
}else{
double result=0;
double start=0;
double end=1e10;
for(int i=1;i<=300;i++){
double mid=(start+end)/2;
if(check(mid,p,n)){
result=mid;
start=mid;
}else{
end=mid;
}
}
pw.println(result);
}
pw.flush();
}
}
static boolean check(double k,int p,int n){
double sum=0;
double time=k;
for(int i=0;i<n;i++){
double t=sto[i]*1.0/cost[i];
if(t-time<eps){
sum+=(time-t)*cost[i];
}
}
if(sum-time*p<eps)return true;
else return false;
}
}