P3743 怎么总是输出0啊,路过dalao帮帮忙。感谢
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(int x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
return;
}
const int maxN = 1E5+10;
const double minN = 1E-6;
int N;
double P,a[maxN],b[maxN];
bool ch(double n){
double s = 0;
for(int i = 0; i < N; ++ i)s += (a[i]*n > b[i])*(a[i]*n-b[i]);
return s<=P*n;
}
double s,t,m;
signed main(){
N = read();
for(int i = 0; i < N; ++ i){
cin>>a[i]>>b[i];
s += a[i];
}
if(s <= P){
cout<<-1; return 0;
}
s = 0;
while(t-s > minN){
m = (t+s)/2;
if(ch(m))s = m;
else t = m;
}
cout<<fixed<<setprecision(10)<<s;
return 0;
}