Skip to content

Instantly share code, notes, and snippets.

@mob5566
Created April 25, 2014 17:00
Show Gist options
  • Save mob5566/11296316 to your computer and use it in GitHub Desktop.
Save mob5566/11296316 to your computer and use it in GitHub Desktop.
Megacity
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define EPS 1e-7
const int dcmp( const double x )
{
if( x < -EPS ) return -1;
return x > EPS;
}
struct Point {
double x, y;
int p;
double d;
Point( double _x = 0, double _y = 0, int _p = 0, double _d = 0 ):
x(_x), y(_y), p(_p), d(_d) {}
const bool operator<( const Point &op ) const { return ( dcmp(op.d-d) >= 0 ); }
};
int n, ppl;
Point city[1005];
int main( void )
{
int i;
while( scanf( "%d%d", &n, &ppl ) == 2 ) {
for( i = 0; i < n; ++i ) {
scanf( "%lf%lf%d", &city[i].x, &city[i].y, &city[i].p );
city[i].d = sqrt( city[i].x*city[i].x+city[i].y*city[i].y );
}
sort( city, city+n );
for( i = 0; i < n && ppl < 1e6; ++i ) {
ppl += city[i].p;
}
if( i == n && ppl < 1e6 ) puts("-1");
else printf( "%.7lf\n", city[i-1].d );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment