每个点到达圆心的距离固定,最终的半径也一定是某点到达圆心的距离,所以维护好每个点到圆心的距离和权值,按距离排序然后顺次选取即可,记得开ll
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n, m, x, y, v;
void solve() {
cin >> n >> m;
vector<pair<int, int>> ve;
for (int i = 0; i < n; ++i) {
cin >> x >> y >> v;
ve.push_back({x * x + y * y, v});
}
sort(ve.begin(), ve.end());
int sum = 0;
for (const auto p : ve) {
sum += p.second;
if (sum >= m) {
cout << fixed << setprecision(7) << sqrt(p.first) << '\n';
return;
}
}
cout << -1 << '\n';
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
// cin >> __t;
while (__t--)
solve();
return 0;
}

京公网安备 11010502036488号