Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.

The city of Tomsk can be represented as point on the plane with coordinates (0; 0). The city is surrounded with n other locations, the i-th one has coordinates (xiyi) with the population of ki people. You can widen the city boundaries to a circle of radius r. In such case all locations inside the circle and on its border are included into the city.

Your goal is to write a program that will determine the minimum radius r, to which is necessary to expand the boundaries of Tomsk, so that it becomes a megacity.

Input

The first line of the input contains two integers n and s (1 ≤ n ≤ 103; 1 ≤ s < 106) — the number of locatons around Tomsk city and the population of the city. Then n lines follow. The i-th line contains three integers — the xi and yi coordinate values of the i-th location and the number ki of people in it (1 ≤ ki < 106). Each coordinate is an integer and doesn't exceed 104 in its absolute value.

It is guaranteed that no two locations are at the same point and no location is at point (0; 0).

Output

In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.

The answer is considered correct if the absolute or relative error don't exceed 10 - 6.

Sample Input

Input
4 999998
1 1 1
2 2 1
3 3 1
2 -2 1
Output
2.8284271
Input
4 999998
1 1 2
2 2 1
3 3 1
2 -2 1
Output
1.4142136
Input
2 1
1 1 999997
2 2 1
Output
-1

Source

Codeforces Round #242 (Div. 2)

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct sa
{
int k;
double r;
}data[];
bool cmp(sa x,sa y)
{
return x.r<y.r;
}
int main()
{
int i,n,s,a,b;
cin>>n>>s;
for(i=;i<n;i++)
{
cin>>a>>b>>data[i].k;
data[i].r=sqrt(a*a+b*b);
}
sort(data,data+n,cmp);
for(i=;i<n;i++)
{
s+=data[i].k;
if(s>=)
{
printf("%.7lf",data[i].r);
return ;
}
}
cout<<-<<endl;
return ;
}

CodeForces - 424B (贪心算法)的更多相关文章

  1. 贪心算法(Greedy Algorithm)

    参考: 五大常用算法之三:贪心算法 算法系列:贪心算法 贪心算法详解 从零开始学贪心算法 一.基本概念: 所谓贪心算法是指,在对问题求解时,总是做出在当前看来是最好的选择.也就是说,不从整体最优上加以 ...

  2. 算法导论----贪心算法,删除k个数,使剩下的数字最小

    先贴问题: 1个n位正整数a,删去其中的k位,得到一个新的正整数b,设计一个贪心算法,对给定的a和k得到最小的b: 一.我的想法:先看例子:a=5476579228:去掉4位,则位数n=10,k=4, ...

  3. LEETCODE —— Best Time to Buy and Sell Stock II [贪心算法]

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  4. ACM_ICPC hdu-2111(简单贪心算法)

    一道非常简单的贪心算法,但是要注意输入的价值是单位体积的价值,并不是这个物品的总价值!#include <iostream> #include <stdio.h> #inclu ...

  5. 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题

    1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ...

  6. 增强学习贪心算法与Softmax算法

    (一) 这个算法是基于一个概率来对探索和利用进行折中:每次尝试时,以概率进行探索,即以均匀概率随机选取一个摇臂,以的概率进行利用,即以这个概率选择当前平均奖赏最高的摇臂(如有多个,则随机选取). 其中 ...

  7. 【九度OJ】题目1434贪心算法

    题目 本题的贪心算法策略需要深入思考一下 看到题目,最初没有理解题目的要求:看尽量多的完整的节目.尽量多是指数量多,自己理解成观看的时间最长.这样想其实简化了这道题. 正确理解题意后,首先想到的想法是 ...

  8. 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)

    //贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...

  9. 贪心算法(Greedy Algorithm)之最小生成树 克鲁斯卡尔算法(Kruskal&#39;s algorithm)

    克鲁斯卡尔算法(Kruskal's algorithm)是两个经典的最小生成树算法的较为简单理解的一个.这里面充分体现了贪心算法的精髓.大致的流程能够用一个图来表示.这里的图的选择借用了Wikiped ...

随机推荐

  1. BZOJ1022 [SHOI2008]小约翰的游戏John

    Description 小约翰经常和他的哥哥玩一个非常有趣的游戏:桌子上有n堆石子,小约翰和他的哥哥轮流取石子,每个人取 的时候,可以随意选择一堆石子,在这堆石子中取走任意多的石子,但不能一粒石子也不 ...

  2. MVC模式介绍

    MVC是一种通过3个不同部分构造一个软件或组件的理想办法: 1.模型(Model):用于存储数据的对象. 2.视图(View):为模型提供数据显示的对象. 控制器(Controller):负责具体的业 ...

  3. 最小圆覆盖(Smallest Enclosing Discs)

    随机增量算法(a randomized incremental algorithm) #define sqr(x) ((x)*(x)) #define EPS 1e-4 struct P{ doubl ...

  4. ubuntu 12.04 server + OPENACS(TR069)安装配置日记

    1. 有两个叫openacs的, openacs.org下的不是 2. 严格匹配版本:luo@bogon:~$ ls jboss-4.2.3.GA-jdk6.zip  jdk-6u41-linux-i ...

  5. POJ3744Scout YYF I(求概率 + 矩阵快速幂)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6757   Accepted: 1960 Descr ...

  6. java的static块执行时机

    一.误区:简单认为JAVA静态代码块在类被加载时就会自动执行.证错如下: class MyClass1 { static {//静态块 System.out.println("static  ...

  7. 使用jQuery解析JSON数据(由ajax发送请求到php文件处理数据返回json数据,然后解析json写入html中呈现)

    在上一篇的Struts2之ajax初析中,我们得到了comments对象的JSON数据,在本篇中,我们将使用jQuery进行数据解析. 我们先以解析上例中的comments对象的JSON数据为例,然后 ...

  8. mysql-binlog日志恢复数据库

    binlog日志用于记录所有更新了数据或者已经潜在更新了数据的所有语句.语句以“事件”的形式保存,它描述数据更改.当我们因为某种原因导致数据库出现故障时,就可以利用binlog日志来挽回(前提是已经配 ...

  9. BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler错误的解决方法

    出现这个问题是因为我的spring3.0里的包是单独引用的,缺少了别的包 譬如Configuration problem: Unable to locate Spring NamespaceHandl ...

  10. POP3,全名为“Post Office Protocol - Version 3”,即“邮局协议版本3”

    POP3 锁定 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . POP3,全名为“Post Office Protocol - Version 3”,即“邮局协议版本3”.是TCP/IP ...