0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 18:11:59 +00:00

P3743 kotori的设备

R44571071
This commit is contained in:
Baoshuo Ren 2021-01-03 14:30:50 +08:00 committed by Baoshuo Ren
parent b9e1270a22
commit 4f526ea189
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,40 @@
#include <bits/stdc++.h>
using namespace std;
int n;
double p, a[100005], b[100005];
double sum, l, r = 1e10, mid;
bool check(double mid) {
double q = mid * p;
sum = 0;
for (int i = 0; i < n; i++) {
if (a[i] * mid > b[i]) {
sum += a[i] * mid - b[i];
}
}
return sum <= q;
}
int main() {
cin >> n >> p;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sum += a[i];
}
if (sum <= p) {
cout << -1 << endl;
return 0;
}
while (r - l > 1e-6) {
mid = (l + r) / 2;
if (check(mid)) {
l = mid;
} else {
r = mid;
}
}
cout << fixed << setprecision(10) << l << endl;
return 0;
}