只有第17个测试点错了求助
查看原帖
只有第17个测试点错了求助
628730
potatotea楼主2023/1/23 18:27
#include<iostream>
using namespace std;

int n, p;
int a[(int)1e5 + 5][2];

bool judge(double time) {
    double sum1(0);
    for (int i = 0; i < n; i++) {
        if (a[i][0] * time > a[i][1]) sum1 += a[i][0] * time - a[i][1];
        if (sum1 > time * p) return false;
    }
    return true;
}

void solve() {
    double left(0), right(1e10), mid;
    while (right - left > 1e-6) {
        mid = left + (right - left) / 2;
        if (judge(mid)) left = mid;
        else right = mid;
    }
    cout << left * 1.0;
}

int main() {
    ios::sync_with_stdio(false);
    long long sum = 0;
    while (cin >> n) {
        cin >> p;
        for (int i = 0; i < n; i++) {
            cin >> a[i][0] >> a[i][1];
            sum += a[i][0];
        }

        if (sum <= p) {
            cout << -1 * 1.0 << endl;
            continue;
        }

        solve();
    }
    return 0;
}
2023/1/23 18:27
加载中...