1、就是排个序再加个循环。。。懒得说了。。。
#include<cstdio>
#include<algorithm>#include<cmath>
using namespace std;
struct city{
double r;
int p;
bool operator<(const city &b)const{
return r<b.r;
}
}a[1010];
int main(){
int n,s,cnt=0;
scanf("%d%d",&n,&s);
s=1000000-s;
for(int i=0;i<n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
double r=sqrt(x*x+y*y);
a[i].r=r;
a[i].p=z;
}
sort(a,a+n);
bool flag=false;
int temp=0;
for(int i=0;i<n;i++){
s-=a[i].p;
if(s<=0){
printf("%f\n",a[i].r);
flag=true;
break;
}
}
if(!flag) printf("-1\n");
return 0;
}