mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 20:56:37 +00:00
P3743 kotori的设备
R44571071
This commit is contained in:
parent
b9e1270a22
commit
4f526ea189
40
Luogu/problem/P3743/P3743.cpp
Normal file
40
Luogu/problem/P3743/P3743.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user