二分半径,o(n) check在圆内点的权值是否大于x即可。

#include<bits/stdc++.h>
#define int long long
// #define double long double
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> PII;
const int N = 3e5 + 10;
const int M = 1e3 + 10;
int mod = 1e9 + 7;
struct Link {
    double x, y, v;
} a[N];

void solve() {
    int n;
    cin >> n;
    int x;
    cin >> x;
    int s = 0;
    for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].v, s += a[i].v;
    if (s < x) {
        cout << -1 << "\n";
        return;
    }
    double l = 0, r = 1e12;
    int idx = 60;
    while (idx--) {
        double mid = (l + r) / 2.0;
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            double dis = (a[i].x) * (a[i].x) + (a[i].y) * (a[i].y);
            if (dis <= mid * mid) sum += a[i].v;
        }
        if (sum >= x) r = mid;
        else l = mid;
    }
    cout << fixed << setprecision(10) << l << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int _;
    _ = 1;
    //cin>>_;
    while (_--) {
        solve();
    }
}