P28317 [洛谷] Bird's Devices
普及+
题目描述

Problem Background

Bird has $n$ devices that can be used simultaneously.

Problem Description

The $i$-th device consumes $a_i$ units of energy per second. The energy consumption is continuous, meaning that energy is not consumed suddenly at a moment but rather at a constant rate. Therefore, for any real number, the amount of energy consumed in $k$ seconds is $k \times a_i$ units. At the beginning, the $i$-th device contains $b_i$ units of energy.

Bird also has a portable charger that can charge any device, providing $p$ units of energy per second to the connected device. The charging process is also continuous and does not need further explanation. Bird can charge any device at any time, and the time taken to switch from one device to another is negligible.

Bird wants to use all these devices together until one of them runs out of energy. Therefore, Bird wants to know, with the help of the charger, how long she can use these devices simultaneously before one of them runs out of energy.

Input Format

The first line contains two integers $n$ and $p$.

The next $n$ lines, each representing a device, contain two integers, which are $a_i$ and $b_i$ for that device.

Output Format

If Bird can use these devices indefinitely, output $-1$.

Otherwise, output the maximum duration Bird can use these devices before one of them runs out of energy.

Let your answer be $a$ and the standard answer be $b$. You will get full marks for this test case if $a$ and $b$ satisfy $\dfrac{|a-b|}{\max(1,b)} \leq 10^{-4}$.

Sample Input and Output

Sample Input #1

2 1
2 2
2 1000

Sample Output #1

2.0000000000

Sample Input #2

1 100
1 1

Sample Output #2

-1

Sample Input #3

3 5
4 3
5 2
6 1

Sample Output #3

0.5000000000

Notes

For $100\%$ of the data, $1 \leq n \leq 100000$, $1 \leq p \leq 100000$, $1 \leq a_i, b_i \leq 100000$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 1 2 2 2 1000
样例输出
2.0000000000