一直WA一个点,自闭了
查看原帖
一直WA一个点,自闭了
300098
cmaths楼主2021/12/18 21:14
#include <cstdio>
#include <algorithm>

int n;
double p, a[100005], b[100005];
bool judge(double time)
{
	double tot = 0, need = time * p;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] * time > b[i])
		{
			tot += a[i] * time - b[i];
			if(tot > need)
			{
				return 0;
			}
		}
	}
	return 1;
}
int main()
{
	double l = 0, r = 1e10, mid;
	double tot = 0;
	scanf("%d %lf", &n, &p);
	for(int i = 1; i <= n; i++)
	{
		scanf("%lf %lf\n", &a[i], &b[i]);
		tot += a[i];
	}
	if(tot < p)
	{
		printf("-1");
		return 0;
	}
	while(r - l > 1e-6)
	{
		mid = (l + r) / 2;
		if(judge(mid))
		{
			l = mid;
		}
		else
		{
			r = mid;
		}
	}
	printf("%lf", l);
	return 0;
}

救救孩子

2021/12/18 21:14
加载中...