95 pts 求调
查看原帖
95 pts 求调
1251715
Moss345512楼主2025/7/25 18:47

Record
Code:

#include<cstdio>
#include<algorithm>
using namespace std;
const double M=0.0000000001;
int n;
double l=0,r=1e9,mid,p,a[200025],b[200025],tmp;
bool chk(double x){
    tmp=0;
    for(int i=1;i<=n;i++){
        if(b[i]-a[i]*x>=0)continue;
        else tmp+=a[i]*x-b[i];
        if(tmp>x*p)return false;
    }
    return tmp<=x*p;
}
int main(){
    scanf("%d %lf",&n,&p);
    for(int i=1;i<=n;i++)scanf("%lf %lf",&a[i],&b[i]),tmp+=a[i];
    if(tmp<=p){
        printf("-1");
        return 0;
    }
    while(r-l>M){
        mid=(l+r)/2;
        if(chk(mid))l=mid;
        else r=mid;
    }
    printf("%lf",l);
    return 0;
}
2025/7/25 18:47
加载中...