思路:对于所有给定点算出到原点的距离,然后排序,采用贪心思想,从小到大的扩充人数,直至到达one million
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
const int maxn = 1000000;
map<double, int>mp;
double dist(int x,int y){
if(x < 0)
x = -x;
if(y < 0)
y = -y;
return sqrt(x*x + y*y);
}
int main(){
int n,s;
while(~scanf("%d%d",&n,&s)){
int x,y,k;
for(int i = 0;i < n;i++){
scanf("%d%d%d",&x,&y,&k);
mp[dist(x, y)] += k;
}
map<double, int>::iterator it;
double ans = -1;
for(it = mp.begin();it != mp.end();it++){
if(s >= maxn)
break;
s += it->second;
ans = it->first;
//printf("%.7lf %d\n",it->first,it->second);
}
if(s < maxn)
printf("-1\n");
else
printf("%.7lf\n",ans);
}
return 0;
}