求助#19,pts95
查看原帖
求助#19,pts95
592342
WA_automat楼主2022/8/23 17:41
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
const int N = 1e5 + 10, INF = 1e10;
int n;
double p;
struct node { double a, b; }m[N];
bool check(double x) {
	double power = p * x;
	for (int i = 1; i <= n; ++i) {
		double now = m[i].b - x * m[i].a;
		if (now < 0) power -= abs(now);
	}
	if (power < 0) return false;
	return true;
}
int main(void) {
	cin >> n >> p;
	for (int i = 1; i <= n; ++i) {
		cin >> m[i].a >> m[i].b;
	}
	double l = 0, r = INF;
	while (r - l > 1e-6) {
		double mid = (l + r) / 2;
		if (check(mid)) l = mid;
		else r = mid;
	}
	if (l >= INF / 2) cout << -1 << endl;
	else cout << setprecision(10) << l << endl;
	return 0;
}
2022/8/23 17:41
加载中...