CF772A.Voltage Keepsake
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have n devices that you want to use simultaneously.
The i-th device uses a__i units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·a__i units of power. The i-th device currently has b__i 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.
你有 n 个设备,希望同时使用它们。
第 i 个设备每秒消耗 ai 单位电量。该消耗是连续的,即在 λ 秒内,该设备将消耗 λ⋅ai 单位电量。第 i 个设备当前储存有 bi 单位电量。所有设备均可储存任意数量的电量。
你有一个充电器,一次只能连接一个设备。该充电器每秒为所连接的设备充入 p 单位电量。充电过程也是连续的,即若将某设备充电 λ 秒,则其电量将增加 λ⋅p 单位。你可以在任意时刻(包括任意实数时刻)切换充电器所连接的设备,且切换所需时间可忽略不计。
你想知道:最多能同时使用这些设备多长时间,直到其中某个设备的电量降至 0。
若可以无限期地使用这些设备,请输出 -1;否则,请输出任一设备电量降至 0 所能维持的最长时间。
输入格式
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 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 a__i and b__i (1 ≤ a__i, b__i ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
第一行包含两个整数 n 和 p(1≤n≤100000,1≤p≤109)—— 分别表示设备的数量和充电器的功率。
接下来是 n 行,每行包含两个整数。第 i 行包含整数 ai 和 bi(1≤ai,bi≤100000)—— 分别表示第 i 台设备的功率以及其初始存储的电量。
输出格式
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
.
如果可以无限期地使用这些设备,则输出 −1;否则,输出任意一个设备电量降至 0 之前所能维持的最长时间。
若您的答案的绝对误差或相对误差不超过 10−4,则视为正确。
即,假设您的答案为 a,评测组的标准答案为 b,当满足
时,评测程序将判定您的答案正确。
输入输出样例
输入#1
2 1 2 2 2 1000
输出#1
2.0000000000
输入#2
1 100 1 1
输出#2
-1
输入#3
3 5 4 3 5 2 6 1
输出#3
0.5000000000
说明/提示
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
在样例测试 1 中,你可以对第一台设备持续充电,直至其电量降至零。第二台设备的初始电量足以支撑这段时间,无需充电。
在样例测试 2 中,你可以无限期地使用该设备。
在样例测试 3 中,我们可以先对第三台设备充电 2/5 秒,然后切换为对第二台设备充电 1/10 秒。
输入解题思路,AI测评打分。不知道怎么写?