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 (x_{i}, y_{i}) with the population of k_{i} 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 ≤ 10^3; 1 ≤ s < 10^6) — 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 x_{i} and y_{i} coordinate values of the i-th location and the number k_{i} of people in it (1 ≤ k_{i} < 10^6). Each coordinate is an integer and doesn't exceed 10^4 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}.


-----Examples-----
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 | Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms


Solutions:
import math
(n, s) = tuple(map(int, input().split()))
x = []
y = []
k = []
r = []
for i in range(n):
	(a, b, c) = tuple(map(int, input().split()))
	x.append(a)
	y.append(b)
	k.append(c)
	r.append((math.sqrt(x[i] ** 2 + y[i] ** 2), i))
r.sort()
nas = s
i = 0
while i < n and nas < 1000000:
	nas += k[r[i][1]]
	i += 1
if i == n and nas < 1000000:
	print('-1')
else:
	print(r[i - 1][0])


import sys
(n, s) = map(int, input().split())
sqr_r = 0
arounds = []
total = s
for _ in range(n):
	(x, y, k) = map(int, input().split())
	arounds.append([x ** 2 + y ** 2, k])
	total += k
if total < 10 ** 6:
	print(-1)
	sys.exit()
arounds.sort()
for i in range(n):
	if s >= 10 ** 6:
		break
	s += arounds[i][-1]
	sqr_r = arounds[i][0]
print(sqr_r ** 0.5)


import math
(n, s) = map(int, input().split())

class Boundary:

	def __init__(self, x, y, population):
		self.radius = round(math.sqrt(x * x + y * y), 7)
		self.population = population

	def __lt__(self, other):
		return self.radius < other.radius
arr = []
for i in range(n):
	(x, y, population) = map(int, input().split())
	arr.append(Boundary(float(x), float(y), population))
populationNeed = 1000000 - s
sum = 0
resultRadius = 0.0
arr.sort()
for i in range(len(arr)):
	sum += arr[i].population
	if sum >= populationNeed:
		resultRadius = arr[i].radius
		break
if sum >= populationNeed:
	print(resultRadius)
else:
	print(-1)


from math import sqrt
(n, s) = map(int, input().split())
dist = 0
d = dict()
for _ in range(n):
	(a, b, c) = map(int, input().split())
	square_dist = a * a + b * b
	if square_dist in d:
		d[square_dist] += c
	else:
		d[square_dist] = c
res = -1
sorted_d = sorted(d)
for it in sorted_d:
	s += d[it]
	if s >= 1000000:
		res = sqrt(int(it))
		break
print(res)


import math
(n, s) = map(int, input().split())

class city:
	d = 0
	k = 0
cities = []

def sortcity(citysort):
	return citysort.d
for i in range(n):
	(x, y, z) = map(int, input().split())
	c = city()
	c.d = math.sqrt(pow(x, 2) + pow(y, 2))
	c.k = z
	cities.append(c)
if s >= 1000000:
	print(0)
else:
	cities.sort(key=sortcity)
	i = 0
	while s < 1000000 and i < n:
		s += cities[i].k
		i += 1
	if s < 1000000:
		print(-1)
	else:
		print(cities[i - 1].d)


def binsearch(nums, target):
	left = 0
	right = len(nums) - 1
	while left <= right:
		mid = (left + right) // 2
		if nums[mid][1] == target:
			return mid
		elif nums[mid][1] > target:
			right = mid - 1
		elif nums[mid][1] < target:
			left = mid + 1
	return left
(n, s) = map(int, input().split())
c = [0, 0]

def euclideandistance(p1, p2):
	import math
	(x1, y1, x2, y2) = (p1[0], p1[1], p2[0], p2[1])
	diffx = (x2 - x1) ** 2
	diffy = (y2 - y1) ** 2
	d = math.sqrt(diffx + diffy)
	return d
lst = []
cities = []
for city in range(n):
	(x, y, k) = map(int, input().split())
	d = euclideandistance(c, [x, y])
	cities.append([d, k])
lstpop = 0
cities.sort()
for i in cities:
	lstpop += i[1]
	i[1] = lstpop
invs = 1000000 - s
pl = binsearch(cities, invs)
if pl >= len(cities):
	print(-1)
	exit()
print(cities[pl][0])


(n, p) = map(int, input().split())
city = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	city.append([(x * x + y * y) ** 0.5, k])
city.sort(key=lambda x: x[0])
mega = False
for i in range(n):
	p += city[i][1]
	if p >= 10 ** 6:
		mega = True
		print('%.7f' % city[i][0])
		break
if not mega:
	print('-1')


from math import sqrt
(n, p) = map(int, input().split())
l = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	v = x ** 2 + y ** 2
	v2 = sqrt(v)
	l.append((v2, k))
l = sorted(l, key=lambda x: x[0])
if p >= 10 ** 6:
	print(0)
	exit(0)
for i in range(len(l)):
	p += l[i][1]
	if p >= 10 ** 6:
		print(l[i][0])
		break
else:
	print('-1')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, p) = map(int, input().split())
ans = []
m = 0
for i in range(n):
	(x, y, r) = map(int, input().split())
	var = (x ** 2 + y ** 2) ** 0.5
	ans.append((var, r))
	m = max(m, var)
ans = sorted(ans)
cnt = p
for i in range(n):
	cnt += ans[i][1]
	if cnt >= 10 ** 6:
		print('%.8f' % ans[i][0])
		exit()
print(-1)


(n, s) = map(int, input().split())
d = {}
l = []
counter = 0
for i in range(n):
	(a, b, c) = map(int, input().split())
	dist = (a ** 2 + b ** 2) ** 0.5
	if dist not in d:
		l.append([dist, c])
		d[dist] = counter
		counter += 1
	else:
		l[d[dist]][1] += c
l.sort()
left = 0
right = len(l) - 1
ans = -1
for i in range(len(l)):
	if s + sum((x[1] for x in l[:i + 1])) >= 1000000:
		ans = l[i][0]
		break
print(ans)


import math

def main():
	(N, S) = [int(x) for x in input().split()]
	mega = 1000000
	cities = []
	for _ in range(N):
		(x, y, k) = [int(x) for x in input().split()]
		rad_sq = x * x + y * y
		cities.append((rad_sq, k))
	cities.sort(key=lambda x: x[0])
	rad = 0
	for citi in cities:
		S += citi[1]
		if S >= mega:
			rad = citi[0]
			break
	if rad > 0:
		print('{:.7f}'.format(math.sqrt(rad)))
	else:
		print(-1)
main()


from math import *
R = lambda : map(int, input().split())
(n, s) = R()
x = sorted(((hypot(x, y), k) for (x, y, k) in (R() for i in range(n))))
for t in x:
	s += t[1]
	if s >= 1000000:
		print(t[0])
		exit()
print(-1)


import math as Math
from sys import stdin
(n, s) = map(int, stdin.readline().strip().split())
points = dict()
for i in range(0, n):
	(x, y, pop) = map(int, stdin.readline().strip().split())
	rad = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))
	if points.get(rad) == None:
		points[rad] = pop
	else:
		points[rad] = points.get(rad) + pop
reached = False
for i in sorted(points.keys()):
	s = s + points[i]
	if s >= 1000000:
		print(format(i, '.7f'))
		reached = True
		break
if reached == False:
	print('-1')


import math
R = lambda : map(int, input().split())
(n, sum) = R()
x = []
y = []
z = []
dis = []
for i in range(n):
	(a, b, c) = R()
	x.append(a)
	y.append(b)
	z.append(c)
	dis.append((math.sqrt(a ** 2 + b ** 2), i))
dis.sort()
i = 0
while sum < 1000000 and i < n:
	sum += z[dis[i][1]]
	i += 1
if sum < 1000000:
	print('-1')
else:
	print(dis[i - 1][0])


import math

class Circle:

	def __init__(self, x, y, s):
		self.x = x
		self.y = y
		self.r = math.sqrt(x ** 2 + y ** 2)
		self.s = s

	def __lt__(self, other):
		return self.r < other.r

def findRadius(a, l, r, x):
	ans = 0
	while l <= r:
		mid = (l + r) // 2
		temp = 0
		for i in range(0, mid + 1, 1):
			temp += a[i].s
		if temp == need:
			return a[mid].r
		elif temp > need:
			r = mid - 1
			ans = mid
		else:
			l = mid + 1
	if ans == 0 and a[0].s < x:
		return -1
	return a[ans].r
(n, s) = map(int, input().split())
need = int(1000000.0 - s)
list_n = []
for _ in range(n):
	(x, y, k) = list(map(int, input().split()))
	c = Circle(x, y, k)
	list_n.append(c)
list_n.sort()
r = findRadius(list_n, 0, n - 1, need)
print('{:.7f}'.format(r)) if r != -1 else print(-1)


from math import sqrt
(n, s) = map(int, input().split())
dis = []
for _ in range(n):
	(x, y, p) = map(int, input().split())
	dt = sqrt((x - 0.0) ** 2 + (y - 0.0) ** 2)
	dis.append((dt, p))
dis.sort()
r = -1
i = 0
le = len(dis)
while s < 10 ** 6 + 1 and i < le:
	s += dis[i][1]
	r = dis[i][0]
	i += 1
	if s >= 10 ** 6:
		i += n
if s < 10 ** 6:
	r = -1
print(r)


def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, m) = MAP()
l = []
k = 0
for i in range(n):
	(x, y, z) = MAP()
	k += z
	d = sqrt(pow(x, 2) + pow(y, 2))
	l.append([d, z])
if m == 10 ** 6:
	print(0)
elif k + m < 1000000:
	print('-1')
else:
	l.sort(key=lambda x: x[0])
	sm = m
	i = 0
	while sm < 10 ** 6 and i < n:
		sm += l[i][1]
		i += 1
	print(l[i - 1][0])


def getRequiredDis(cities, need):
	sum = 0
	for i in range(len(cities)):
		sum += cities[i][2]
		if sum >= need:
			return cities[i][-1]
			break
	return -1
s = (0, 0)
import math
(n, s) = list(map(int, input('').split()))
cities = []
for _ in range(n):
	city = list(map(int, input('').split()))
	(x, y, p) = city
	dis = math.sqrt(x ** 2 + y ** 2)
	cities.append((x, y, p, dis))
cities = sorted(cities, key=lambda x: x[-1])
need = 10 ** 6 - s
print(getRequiredDis(cities, need))


(n, s) = map(int, input().split())
population = s
rs = dict()
success = False
for i in range(n):
	(x, y, k) = map(int, input().split())
	r = x ** 2 + y ** 2
	if r in rs:
		rs[r] += k
	else:
		rs[r] = k
for key in sorted(rs.keys()):
	population += rs[key]
	if population >= 1000000:
		print('{:.7f}'.format(key ** 0.5))
		success = True
		break
if not success:
	print(-1)


(n, s) = map(int, input().split())
arr = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	arr.append((x ** 2 + y ** 2, k))
arr.sort()
(res, idx, r) = (0, 0, 0)
while idx < n and s + res < 1000000.0:
	r = arr[idx][0]
	res += arr[idx][1]
	idx += 1
print(r ** 0.5 if s + res >= 1000000.0 else -1)


import math

class Location:

	def __init__(self, r, k):
		self.r = r
		self.k = k

	def __lt__(self, other):
		return self.r < other.r

def solution():
	(n, s) = map(int, input().split())
	locations = []
	for i in range(n):
		(x, y, k) = map(int, input().split())
		locations.append(Location(math.sqrt(x * x + y * y), k))
	locations.sort()
	min_r = 0
	for i in range(n):
		if s >= 1000000:
			print(round(min_r, 7))
			return
		s += locations[i].k
		min_r = locations[i].r
	if s >= 1000000:
		print(round(min_r, 7))
	else:
		print(-1)
solution()


def cmp(key):
	return key[0]
(n, s) = [int(hoiii) for hoiii in input().split()]
hmmmm = []
for i in range(n):
	(x, y, k) = [int(hoi) for hoi in input().split()]
	hmmmm.append(((x ** 2 + y ** 2) ** 0.5, k))
hmmmm.sort(key=cmp)
megamillion = 1000000 - s
naswer = 0
for i in hmmmm:
	if megamillion <= 0:
		break
	else:
		megamillion = megamillion - i[1]
		naswer = i[0]
if megamillion <= 0:
	print(naswer)
else:
	print(-1)


(n, s) = map(int, input().split())
points = [list(map(int, input().split())) for i in range(n)]
points = sorted(points, key=lambda a: a[0] * a[0] + a[1] * a[1])
(x, y) = (0, 0)
for p in points:
	(x, y) = (p[0], p[1])
	s += p[2]
	if s >= 10 ** 6:
		break
import math
print(-1 if s < 10 ** 6 else format(math.sqrt(x * x + y * y), '.7f'))


import math
(n, s) = list(map(int, input('').split()))
L = []
for i in range(n):
	(x, y, z) = list(map(int, input('').split()))
	L += [(math.sqrt(x * x + y * y), z)]
L.sort()
count = s
if s >= 1000000:
	print('0')
	return
for i in L:
	count += i[1]
	if count >= 1000000:
		print(i[0])
		return
print('-1')


from math import sqrt
(n, s) = map(int, input().split())
city = [[0.0, s]]
for i in range(n):
	(x, y, k) = map(int, input().split())
	city.append([sqrt(x * x + y * y), k])
city.sort(key=lambda x: x[0])
for i in range(1, n + 1):
	city[i][1] += city[i - 1][1]
lf = 0
rg = n
if city[rg][1] < 1000000:
	print(-1)
else:
	while rg - lf >= 3:
		mid = (lf + rg) // 2
		if city[mid][1] >= 1000000:
			rg = mid
		else:
			lf = mid
	for i in range(lf, rg + 1):
		if city[i][1] >= 1000000:
			print(city[i][0])
			break


def func(x):
	global a
	y = 0
	for i in range(x):
		y += a[i][1]
	return y
(n, s) = map(int, input().split())
a = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	a.append([x * x + y * y, k])
if func(n) + s < 10 ** 6:
	print(-1)
	exit(0)
a.sort()
l = -1
r = n
while l + 1 < r:
	m = (l + r) // 2
	if s + func(m + 1) >= 10 ** 6:
		r = m
	else:
		l = m
print(a[r][0] ** 0.5)


import sys, threading, os.path
import string
import collections, heapq, math, bisect
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	(n, s) = list(map(int, input.readline().split()))
	data = []
	for i in range(n):
		temp_list = list(map(int, input.readline().split()))
		data.append((math.sqrt(math.pow(temp_list[0], 2) + math.pow(temp_list[1], 2)), temp_list[2]))
	data.sort()
	res = -1
	for (x, y) in data:
		s += y
		if s >= 1000000:
			res = x
			break
	if res == -1:
		output = res
	else:
		output = format(res, '.7f')
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


import math
(n, m) = map(int, input().split())
L = []
for i in range(n):
	(x, y, z) = map(int, input().split())
	L.append((math.sqrt(x * x + y * y), z))
L.sort()
count = m
if count >= 1000000:
	print('0')
	exit()
for i in L:
	count += i[1]
	if count >= 1000000:
		print(i[0])
		exit()
print('-1')


from math import sqrt

class Location:

	def __init__(self, x, y, population):
		self.x = x
		self.y = y
		self.population = population
		self.dist = sqrt(x ** 2 + y ** 2)
(n, s) = map(int, input().split())
places = []
for _ in range(n):
	(x, y, k) = map(int, input().split())
	places.append(Location(x, y, k))
places.sort(key=lambda l: l.dist)
radius = -1
for location in places:
	(x, y, k, r) = (location.x, location.y, location.population, location.dist)
	if s + k >= int(1000000.0):
		radius = r
		break
	else:
		s += k
print('{:.7f}'.format(radius))


import math
(n, current_pop) = [int(i) for i in input().split()]
sur_area = {}
for i in range(n):
	(a, b, c) = [int(j) for j in input().split()]
	r = a ** 2 + b ** 2
	if r not in sur_area:
		sur_area[r] = c
	else:
		sur_area[r] += c
key = sorted(sur_area.keys())
for i in key:
	current_pop += sur_area[i]
	if current_pop >= 1000000:
		print(round(math.sqrt(i), 7))
		exit()
print(-1)


from math import sqrt

def sort_fun(el):
	return sqrt(el[0] ** 2 + el[1] ** 2)

def main():
	(cities, population) = [int(x) for x in input().split(' ')]
	data = []
	for _ in range(cities):
		data.append([int(x) for x in input().split(' ')])
	data.sort(key=sort_fun)
	for (x, y, inc_pop) in data:
		population += inc_pop
		if population >= 1000000:
			print(sqrt(x ** 2 + y ** 2))
			return
	print(-1)
main()


import sys
import math
[L, pop] = [int(n) for n in sys.stdin.readline().split()]
locations = []
for l in range(L):
	[x, y, k] = [int(n) for n in sys.stdin.readline().split()]
	radius = math.sqrt(x ** 2 + y ** 2)
	locations.append((radius, k))
locations = sorted(locations)
didit = False
if pop >= 1000000:
	print(0)
else:
	for (r, n) in locations:
		pop += n
		if pop >= 1000000:
			print(r)
			didit = True
			break
if not didit:
	print(-1)


import math
(n, s) = map(int, input().split())
d = dict()
for i in range(n):
	(x, y, k) = map(int, input().split())
	if not x * x + y * y in d:
		d[x * x + y * y] = k
	else:
		d[x * x + y * y] += k
flag = False
a = []
for key in d.keys():
	a.append(key)
a.sort()
for x in a:
	s += d[x]
	if s >= 1000000.0:
		print('{0:.7}'.format(math.sqrt(x)))
		flag = True
		break
if not flag:
	print(-1)


(n, s) = map(int, input().split())
l = []
for _ in range(n):
	(a, b, k) = map(int, input().split())
	l.append(((a ** 2 + b ** 2) ** 0.5, k))
for x in sorted(l):
	s += x[1]
	if s >= 1000000:
		print(x[0])
		break
else:
	print(-1)


import math
(n, s) = map(int, input().strip().split(' '))
l = []
for i in range(n):
	(x, y, k) = map(int, input().strip().split(' '))
	l1 = []
	l1 = [math.sqrt(x * x + y * y), k]
	l.append(l1)
l.sort(key=lambda l: l[0])
t = -1
f = 0
for i in range(n):
	t = l[i][0]
	s += l[i][1]
	if s >= 1000000:
		f = 1
		print(t)
		break
if f == 0:
	print(-1)


from math import sqrt
(n, s) = map(int, input().split())
M = dict()
for i in range(n):
	(x, y, k) = map(int, input().split())
	if x * x + y * y in M:
		M[x * x + y * y] += k
	else:
		M[x * x + y * y] = k
for (key, value) in sorted(M.items()):
	s += value
	if s >= 1000000:
		print('%.10f' % sqrt(key))
		exit(0)
print(-1)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter
import math
import heapq
from heapq import heappop, heappush
import bisect
from itertools import groupby

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a / gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def Bs(a, x):
	i = 0
	j = 0
	left = 1
	right = k
	flag = False
	while left < right:
		mi = (left + right) // 2
		if a[mi] <= x:
			left = mi + 1
			i += 1
		else:
			right = mi
			j += 1
	if left > 0 and a[left - 1] == x:
		return (i - 1, j)
	else:
		return (-1, -1)

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a):
	print('? {}'.format(a), flush=True)
	n = lint()
	return n

def bstemp(n, k):
	l = 1
	r = n + 1
	while l < r:
		mid = (l + r) // 2
		if mid * (mid + 1) * 5 // 2 + k <= 4 * 60:
			l = mid + 1
		else:
			r = mid
	return l

def dfs(i, p):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	if n > 2:
		l.append(n)
	return l
(n, s) = lint()
s = 10 ** 6 - s
a = []
r = 0
for _ in range(n):
	(x, y, k) = lint()
	a.append([math.sqrt(x ** 2 + y ** 2), k])
a.sort()
for i in range(n):
	(_, k) = a[i]
	r += k
	a[i][1] = r
if r < s:
	print(-1)
else:
	(l, r) = (0, n - 1)
	while l < r:
		mid = l + (r - l) // 2
		if a[mid][1] >= s:
			r = mid
		else:
			l = mid + 1
	print(a[r][0])


(n, pop) = list(map(int, input().split()))
arr = []
d = {}
cnt = 0
for i in range(n):
	(x, y, p) = list(map(int, input().split()))
	(x, y) = (abs(x), abs(y))
	cnt += p
	r = (x ** 2 + y ** 2) ** 0.5
	arr.append([r, x, y, p])
arr.sort()
if pop + cnt < 1000000:
	print(-1)
else:
	cnt = 0
	for i in arr:
		(r, x, y, p) = (i[0], i[1], i[2], i[3])
		cnt += p
		if cnt + pop >= 10 ** 6:
			(u, v) = (x, y)
			break
	r = (u ** 2 + v ** 2) ** 0.5
	print(r)


from collections import defaultdict
import math
(n, people) = map(int, input().split())
(maps, maps_sum) = (defaultdict(list), defaultdict(int))

def radius(x, y):
	return math.sqrt(x * x + y * y)

def sum_p(r):
	s = 0
	for p in maps[r]:
		s += p
	return s
for _ in range(n):
	(x, y, k) = map(int, input().split())
	maps[radius(x, y)].append(k)
for r in maps:
	maps_sum[r] = sum_p(r)
ans = []
for r in maps_sum:
	ans.append([r, maps_sum[r]])
ans.sort()
for i in range(len(ans)):
	people += ans[i][1]
	if people >= 1000000:
		print(ans[i][0])
		exit()
print(-1)


import math
(n, s) = (int(i) for i in input().strip().split())
l = [None] * n
for i in range(n):
	(x, y, p) = list(map(int, input().split()))
	l[i] = (x * x + y * y, p)
l.sort(key=lambda x: x[0])
r = 1000000 - s
for i in l:
	r -= i[1]
	if r <= 0:
		print('%.7f' % math.sqrt(i[0]))
		break
if r > 0:
	print(-1)


ciudades = []
(cantidad, poblacion) = tuple(input().split(' '))
poblacion = int(poblacion)
for i in range(int(cantidad)):
	ciudades.append(input().split(' '))
	ciudades[i][0] = (int(ciudades[i][0]) ** 2 + int(ciudades[i][1]) ** 2) ** 0.5
ciudades.sort()
logrado = False
for i in range(len(ciudades)):
	if poblacion + int(ciudades[i][2]) >= 1000000:
		print(ciudades[i][0])
		logrado = True
		break
	else:
		poblacion = poblacion + int(ciudades[i][2])
if not logrado:
	print('-1')


def main():
	from sys import stdin
	(n, s) = map(int, input().split())
	l = []
	for w in stdin.read().splitlines():
		(x, y, t) = map(int, w.split())
		l.append((x * x + y * y, t))
	l.sort()
	for (r2, t) in l:
		s += t
		if s > 999999:
			print(r2 ** 0.5)
			return
	print(-1)
main()


(n, s) = map(int, input().split())
arr = []
for _ in range(n):
	(a, b, c) = map(int, input().split())
	arr.append([(a, b), c])
arr.sort(key=lambda x: x[0][0] ** 2 + x[0][1] ** 2)
pt = [-1, -1]
for i in range(n):
	if s + arr[i][1] >= 10 ** 6:
		pt = arr[i][0]
		break
	s += arr[i][1]
if pt == [-1, -1]:
	print(-1)
else:
	print(pow(pt[0] ** 2 + pt[1] ** 2, 0.5))


import math
(n, s) = map(int, input().split())
dist = []
for _ in range(n):
	(x, y, k) = map(int, input().split())
	dist.append([math.sqrt(x * x + y * y), k])
left = 1000000 - s
dist.sort(key=lambda x: x[0])
ans = 0
i = -1
while ans < left:
	i += 1
	if i == n:
		break
	ans = ans + dist[i][1]
if i >= 0 and i < n:
	print(dist[i][0])
else:
	print('-1')


(n, s) = map(int, input().split())
city = {}
_sum = 0
for i in range(n):
	(x, y, k) = map(int, input().split())
	if (abs(x), abs(y)) not in city:
		city[abs(x), abs(y)] = k
	else:
		city[abs(x), abs(y)] += k
	_sum += k
need = int(1000000.0) - s
if _sum < need:
	print(-1)
else:
	popular = {}
	(x, y) = (0, 0)
	count = 0
	for i in sorted(city, key=lambda x: (x[0] ** 2 + x[1] ** 2) ** 0.5):
		count += city[i[0], i[1]]
		r = (i[0] ** 2 + i[1] ** 2) ** 0.5
		popular[r] = count
	for i in popular:
		if popular[i] >= need:
			print(i)
			break


def bs(l, h):
	while l < h:
		m = (l + h) // 2
		if a[m][1] >= 10 ** 6 - s:
			h = m
		else:
			l = m + 1
	return l
(n, s) = map(int, input().split())
a = []
for _ in range(n):
	(x, y, p) = map(int, input().split())
	a.append([(x ** 2 + y ** 2) ** 0.5, p])
a.sort()
for i in range(1, n):
	a[i][1] += a[i - 1][1]
if a[-1][1] < 10 ** 6 - s:
	print(-1)
	exit()
if s == 10 ** 6:
	print(0)
	exit()
print(a[bs(0, n - 1)][0])


import math

def inp():
	return map(int, input().split())

def solve():
	(n, total_people) = inp()
	location = dict()
	for i in range(n):
		(x, y, people) = inp()
		r = x * x + y * y
		if not r in location:
			location[r] = people
		else:
			location[r] += people
	R = []
	for r in location:
		R.append(r)
	R.sort()
	for r in R:
		total_people += location[r]
		if total_people >= 1000000:
			print(math.sqrt(r))
			return
	print('-1')
solve()


import math
(n, s) = map(int, input().split())
dis = dict()
for _ in range(n):
	(a, b, c) = map(int, input().split())
	k = a * a + b * b
	if k not in dis:
		dis[k] = c
	else:
		dis[k] += c
for i in sorted(dis.keys()):
	s += dis[i]
	if s >= int(1000000.0):
		print('%.7f' % math.sqrt(i))
		exit()
print(-1)


from math import *
(n, s) = map(int, input().split())
k = [0] * 1001
x = [0] * 1001
y = [0] * 1001
r0 = 0
r = 0
count = 0
Minr = 1000000
otv = -1
for i in range(n):
	(x[i], y[i], k[i]) = map(int, input().split())
for i in range(n):
	count = s
	r0 = sqrt(x[i] ** 2 + y[i] ** 2)
	for j in range(n):
		r = sqrt(x[j] ** 2 + y[j] ** 2)
		if r <= r0:
			count += k[j]
		if count >= 1000000 and r0 < Minr:
			Minr = r0
			otv = r0
			break
print(otv)


(a, b) = map(int, input().split())
if b >= 10 ** 6:
	exit(print(0))
z = {}
for i in range(a):
	e = tuple(map(abs, map(int, input().split())))
	s = e[:2]
	z[s] = z.get(s, 0) + e[2]
r = [((i[0] ** 2 + i[1] ** 2,),) + i for i in z]
r.sort()
r1 = [z[i[1:]] for i in r]
z = len(r1)
for i in range(1, z):
	r1[i] += r1[i - 1]
lo = 0
hi = z - 1
ans = -1
while lo <= hi:
	mid = (lo + hi) // 2
	if b + r1[mid] >= 10 ** 6:
		ans = mid
		hi = mid - 1
	else:
		lo = mid + 1
if ans == -1:
	print(ans)
else:
	p = r[ans][0]
	print(p[0] ** 0.5)


import math
from collections import defaultdict
(x, y) = map(int, input().split())
r = defaultdict()
for i in range(x):
	(a, b, c) = map(int, input().split())
	a = math.sqrt(pow(a, 2) + pow(b, 2))
	if a not in r:
		r[a] = []
	r[a].append(c)
if y >= 1000000:
	print('0')
else:
	for key in sorted(r):
		for j in range(len(r[key])):
			y += r[key][j]
		if y >= 1000000:
			print(key)
			break
	else:
		print('-1')


from math import sqrt
from sys import exit
(n, s) = input().split(' ')
(n, s) = (int(n), int(s))
radius = []
population = []
for i in range(n):
	(x, y, k) = [int(i) for i in input().split(' ')]
	radius.append(sqrt(x ** 2 + y ** 2))
	population.append(k)
target = 1000000 - s
if target <= 0:
	print(0)
	exit()
if target > sum(population):
	print(-1)
	exit()
sorted_radius = sorted(list(set(radius)))
pop = 0
for distance in sorted_radius:
	for i in range(n):
		if distance == radius[i]:
			pop += population[i]
		if pop >= target:
			print(distance)
			exit()


import math as m
(n, s) = map(int, input().split())
MEGA_CITY = 10 ** 6
cities = []
for _ in range(n):
	params = tuple(map(int, input().split()))
	cities.append(params)
cities.sort(key=lambda dist: m.sqrt(dist[0] ** 2 + dist[1] ** 2))
res = 0.0
current_population = s
for city in cities:
	current_population += city[2]
	if current_population >= MEGA_CITY:
		res = m.sqrt(city[0] ** 2 + city[1] ** 2)
		break
if current_population < MEGA_CITY:
	print('-1')
else:
	print('{0:.7f}'.format(res))


(n, s) = map(int, input().split())
d = {}
for i in range(n):
	(x, y, k) = map(int, input().split())
	dist = (x ** 2 + y ** 2) ** (1 / 2)
	if dist not in d:
		d[dist] = k
	else:
		d[dist] += k
lstKey = sorted(d)
ans = None
for ele in lstKey:
	s += d[ele]
	if s >= 1000000:
		ans = ele
		break
if ans == None:
	print(-1)
else:
	print('%.7f' % ele)


import math
(n, s) = map(int, input().split())
map_dist_pop = dict()
for i in range(n):
	(x, y, p) = map(int, input().split())
	dist = math.sqrt(x ** 2 + y ** 2)
	map_dist_pop[dist] = map_dist_pop.get(dist, 0) + p
sorted_map = [(k, v) for (k, v) in sorted(map_dist_pop.items())]
sum_pop = s
res = -1
for loc in sorted_map:
	sum_pop += loc[1]
	if sum_pop >= 10 ** 6:
		res = loc[0]
		break
print(res)


import math
MEGACITY = 10 ** 6

def getDistanceWithoutSQRT(x, y):
	return x ** 2 + y ** 2
(n, s) = list(map(int, input().split(' ')))
pointDist = dict()
expandDist = -1
for _ in range(n):
	(x, y, k) = list(map(int, input().split(' ')))
	d = getDistanceWithoutSQRT(x, y)
	if d not in pointDist:
		pointDist[d] = 0
	pointDist[d] += k
sortedKeys = sorted(pointDist)
for dist in sortedKeys:
	s += pointDist[dist]
	if s >= MEGACITY:
		expandDist = dist
		break
if expandDist == -1:
	print(-1)
else:
	print('%.7f' % math.sqrt(expandDist))


import math
R = lambda : map(int, input().split())
(n, s) = R()
cities = [tuple(R()) for _ in range(n)]
if sum((x[2] for x in cities)) + s < 10 ** 6:
	print(-1)
	exit()
(l, r) = (0, max((x[0] * x[0] + x[1] * x[1] for x in cities)))
while l < r:
	m = (l + r) // 2
	acc = s + sum((x[2] for x in cities if x[0] * x[0] + x[1] * x[1] <= m))
	if acc < 10 ** 6:
		l = m + 1
	else:
		r = m
print(math.sqrt(r))


import math
(n, s) = tuple(map(int, str.split(input())))
cities = list([tuple(map(int, str.split(input()))) for _ in range(n)])
cities.sort(key=lambda city: city[0] ** 2 + city[1] ** 2)
i = 0
extra = 0
while s + extra < 10 ** 6 and i < n:
	(extra, i) = (extra + cities[i][2], i + 1)
if s + extra < 10 ** 6:
	print(-1)
else:
	(x, y, _) = cities[i - 1]
	print(math.sqrt(x ** 2 + y ** 2))


import queue
import math
(n, s) = map(int, input().split())
pq = queue.PriorityQueue()
for i in range(n):
	(x, y, k) = map(int, input().split())
	r = math.sqrt(x ** 2 + y ** 2)
	pq.put((r, k))
r = 0
while pq.empty() == False and s < 1000000:
	(r, k) = pq.get()
	s += k
if s < 1000000:
	print(-1)
else:
	print('{0:.7f}'.format(r))


import math
(n, s) = input().split()
(n, s) = (int(n), int(s))
m = {}
r1 = -1
for i in range(n):
	(x, y, k) = input().split()
	(x, y, k) = (int(x), int(y), int(k))
	m[i] = (math.sqrt(x * x + y * y), x, y, k)
lm = list(m.items())
lm.sort(key=lambda i: i[1])
for i in range(n):
	try:
		s += lm[i][1][3]
		if s >= 1000000:
			r1 = math.sqrt(lm[i][1][1] * lm[i][1][1] + lm[i][1][2] * lm[i][1][2])
			print(round(r1, 7))
			break
	except:
		i = n - 1
else:
	print(r1)


from collections import defaultdict
from math import hypot
I = lambda : map(int, input().split())
(n, s) = I()
d = defaultdict(int)
for _ in range(n):
	(x, y, k) = I()
	d[hypot(x, y)] += k
for (r, k) in sorted(d.items()):
	s += k
	if s > 999999:
		print(r)
		break
else:
	print(-1)


from sys import stdin, stdout
from math import sqrt
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
sq = lambda x, y: x * x + y * y
mega = 10 ** 6

def fn(rad):
	sm = init
	for (a, b, pop) in l1:
		if sq(a, b) <= rad:
			sm += pop
	if sm >= mega:
		return True
	return False
for _ in range(1):
	(n, init) = lst()
	l1 = [lst() for i in range(n)]
	total = sum((v[2] for v in l1))
	if total + init < mega:
		print(-1)
		continue
	l = 1
	r = 10 ** 12
	while l <= r:
		mid = l + r >> 1
		if fn(mid) == False:
			l = mid + 1
		else:
			r = mid - 1
	print(sqrt(l))


MEGA = 10 ** 6
EPS = 10 ** (-8)

def dist(a, b):
	return pow((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2, 0.5)
(n, p) = map(int, input().split())
o = (0, 0)
city = []
pop = []
lo = 0
hi = 0
for i in range(n):
	(x, y, k) = map(int, input().split())
	city.append((x, y))
	d = dist(o, (x, y))
	hi = max(hi, d)
	pop.append(k)
total = sum(pop) + p
if total < MEGA:
	print(-1)
else:
	while lo + EPS < hi:
		mi = (lo + hi) / 2
		newP = p
		for i in range(n):
			if dist(o, city[i]) <= mi:
				newP += pop[i]
		if newP >= MEGA:
			hi = mi
		else:
			lo = mi
	print('{:.7f}'.format((lo + hi) / 2))


import math
(n, s) = [int(x) for x in input().split()]
cities = []
for i in range(n):
	(x, y, k) = [int(x) for x in input().split()]
	d2 = x ** 2 + y ** 2
	cities.append((d2, k))
cities.sort(key=lambda x: x[0])
if s >= int(1000000.0):
	print(0)
	exit()
while cities:
	t = cities.pop(0)
	s += t[1]
	if s >= int(1000000.0):
		print(math.sqrt(t[0]))
		exit()
print(-1)


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return sorted(list(map(int, input().split())))

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic
(n, s) = di()
l = []
while n:
	n -= 1
	(x, y, k) = di()
	r = math.sqrt(x * x + y * y)
	l.append([r, k])
l.sort()
diff = 1000000 - s
if diff == 0:
	print(0)
else:
	for i in range(len(l)):
		diff -= l[i][1]
		if diff <= 0:
			break
	if diff > 0:
		print(-1)
	else:
		print(l[i][0])


def distance(e):
	return e[3]

def main():
	(n, s) = input().split()
	ciudades = []
	(n, s) = (int(n), int(s))
	for i in range(n):
		(x, y, k) = input().split()
		d = ((int(x) - 0) ** 2 + (int(y) - 0) ** 2) ** 0.5
		ciudades.append((int(x), int(y), int(k), d))
	ciudades.sort(key=distance)
	for i in ciudades:
		if s + i[2] >= 1000000:
			return i[3]
		elif s + i[2] < 1000000:
			s = s + i[2]
		else:
			return -1
	if s < 1000000:
		return -1
print(main())


import math
(n, s) = map(int, input().split())
c = []
for i in range(n):
	(x, y, p) = map(int, input().split())
	c.append([x ** 2 + y ** 2, p])
c.sort()
c[0][1] += s
for i in range(1, n):
	c[i][1] += c[i - 1][1]
l = 0
h = n - 1
while l < h:
	m = (l + h) // 2
	if c[m][1] >= 1000000:
		h = m
	else:
		l = m + 1
if c[l][1] < 1000000:
	print('-1')
else:
	print(math.sqrt(c[l][0]))


import math
import collections
city = dict()

def main():
	(n, s) = map(int, input().split())
	for _ in range(n):
		(x, y, k) = map(float, input().split())
		dist = math.sqrt(x * x + y * y)
		city[dist] = city.get(dist, 0) + k
	for key in sorted(city.keys()):
		if s < 1000000:
			s += city[key]
			if s >= 1000000:
				print(key)
				return 0
	print(-1)
main()


import math
(n, s) = list(map(int, input().split()))
need = 1000000 - s
if need <= 0:
	print('0')
	exit()
c = []
for _ in range(n):
	c.append(list(map(int, input().split())))

def getDist(x, y):
	return math.sqrt(x * x + y * y)
dist = []
for city in c:
	dist.append([getDist(city[0], city[1]), city[2]])
dist.sort()
for d in dist:
	if need - d[1] <= 0:
		print(d[0])
		exit()
	else:
		need -= d[1]
print('-1')


import math

def solve():
	(n, s) = map(int, input().split())
	location = dict()
	for i in range(n):
		(x, y, people) = map(int, input().split())
		r = x * x + y * y
		if r in location:
			location[r] += people
		else:
			location[r] = people
	listR = []
	for r in location:
		listR.append(r)
	listR.sort()
	for r in listR:
		s += location[r]
		if s >= 1000000:
			print(math.sqrt(r))
			return
	print('-1')
solve()


__author__ = 'Lipen'

def main():
	(n, s) = map(int, input().split())
	data = []
	for _ in range(n):
		(x, y, k) = map(int, input().split())
		r = pow(x, 2) + pow(y, 2)
		data.append([x, y, k, r])
	rmin = -1
	for i in range(n):
		count = 0
		r = data[i][3]
		for j in range(n):
			if data[j][3] <= r:
				count += data[j][2]
		if count + s >= 1000000 and (r < rmin or rmin == -1):
			rmin = r
	if rmin == -1:
		print(-1)
	else:
		print(pow(rmin, 0.5))
main()


import math
requirePopulation = 1000000
(n, s) = map(int, input().split())
locations = {}
for i in range(n):
	(x, y, k) = map(int, input().split())
	key = round(math.sqrt(abs(x) * abs(x) + abs(y) * abs(y)), 7)
	if key in locations:
		locations[key] += k
	else:
		locations[key] = k
totalBonus = 0
for i in sorted(locations.keys()):
	totalBonus += locations[i]
	if s + totalBonus >= requirePopulation:
		print(i)
		exit()
print(-1)


import math
(n, s) = map(int, input().split())
locations = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	locations += [(x * x + y * y, k)]
locations.sort()
for i in range(n):
	s += locations[i][1]
	if s >= 1000000:
		print(math.sqrt(locations[i][0]))
		return
print(-1)


import math
(n, s) = [int(c) for c in input().split()]
ar = []
for i in range(n):
	(x, y, count) = [int(c) for c in input().split()]
	ar.append([math.sqrt(x ** 2 + y ** 2), count])
ar.sort(key=lambda _: _[0])
i = 0
while i < n and s < 10 ** 6:
	s += ar[i][1]
	i += 1
if s < 10 ** 6:
	print(-1)
else:
	print(round(ar[i - 1][0], 7))


from sys import stdin, stdout
from math import sqrt
(n, s) = [int(x) for x in stdin.readline().split()]
l = list()
for i in range(n):
	(x, y, k) = [int(x) for x in stdin.readline().split()]
	d = sqrt(pow(x, 2) + pow(y, 2))
	l.append((d, k))
l.sort()
m = 0.0
for i in range(n):
	if s < 1000000:
		s += l[i][1]
		m = l[i][0]
	else:
		break
if s < 1000000:
	stdout.write('-1\n')
else:
	stdout.write(str(m) + '\n')


from sys import stdin, stdout
from math import pow, sqrt

def good(arr1, arr2, target, k):
	(l, r) = (-1, len(arr1))
	while l + 1 < r:
		m = (l + r) // 2
		if arr1[m] <= target:
			l = m
		else:
			r = m
	if l == -1:
		return False
	else:
		return arr2[l] >= k

def main():
	(n, k) = map(int, stdin.readline().strip().split())
	k = 1000000 - k
	city_details = []
	for i in range(n):
		city_details.append([int(num) for num in stdin.readline().strip().split()])
	if k == 0:
		stdin.write('0')
	else:
		d = {}
		for i in city_details:
			rad = pow(i[0], 2) + pow(i[1], 2)
			d[rad] = d.get(rad, 0) + i[2]
		s_r = [sqrt(num) for num in sorted(d.keys(), key=lambda t: t, reverse=False)]
		s_p = [tup[1] for tup in sorted(d.items(), key=lambda t: t[0], reverse=False)]
		p_s = [s_p[0]]
		for i in s_p[1:]:
			p_s.append(p_s[-1] + i)
		if k > p_s[-1]:
			stdout.write('-1')
		else:
			(l, r) = (0, 100000)
			for i in range(60):
				m = (l + r) / 2
				if good(s_r, p_s, m, k):
					r = m
				else:
					l = m
			stdout.write(f'{r}')
main()


def solve(need):
	if need <= 0:
		print(0)
		return
	location = []
	for _ in range(n):
		(x, y, k) = map(int, input().split())
		location.append(((x ** 2 + y ** 2) ** 0.5, k))
	location.sort()
	for (r, population) in location:
		need -= population
		if need <= 0:
			print('{:.7f}'.format(r))
			return
	print(-1)
(n, s) = map(int, input().split())
need = 10 ** 6 - s
solve(need)


from sys import stdin, stdout
from math import sqrt
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
fn = lambda x, y: sqrt(x * x + y * y)
mega = 10 ** 6
for i in range(1):
	(n, init) = lst()
	l = [lst() for i in range(n)]
	l.sort(key=lambda x: fn(x[0], x[1]))
	ans = -1
	for i in range(n):
		init += l[i][2]
		if init >= mega:
			ans = fn(l[i][0], l[i][1])
			break
	print(ans)


import sys
import math
(n, m) = sys.stdin.readline().split()
n = int(n)
m = int(m)

def insertion_sort(array, val):
	right = len(array) - 1
	left = 0
	while left <= right:
		mid = left + (right - left) // 2
		midval = array[mid]
		if midval > val:
			right = mid - 1
		else:
			left = mid + 1
	if left == 0:
		return [val] + array
	elif right == n - 1:
		return array + [val]
	else:
		return array[:left] + [val] + array[left:]
sorted_dist = []
dicti = dict()
for i in range(n):
	(xi, yi, k) = [int(i) for i in sys.stdin.readline().split()]
	dist = math.sqrt(xi ** 2 + yi ** 2)
	if dist in dicti:
		dicti[dist] += k
	else:
		dicti[dist] = k
		sorted_dist = insertion_sort(sorted_dist, dist)
if m >= 1000000:
	print(0)
else:
	breaki = False
	for i in sorted_dist:
		m += dicti[i]
		if m >= 1000000:
			print(i)
			breaki = True
			break
	if breaki == False:
		print(-1)


(n, s) = map(int, input().split(' '))
r = 0
p = s
t = 0
arr = []
for i in range(n):
	(x, y, k) = map(int, input().split(' '))
	arr.append([x, y, k])
arr = sorted(arr, key=lambda z: z[0] ** 2 + z[1] ** 2)
for j in range(n):
	r = (arr[j][0] ** 2 + arr[j][1] ** 2) ** 0.5
	p += arr[j][2]
	if p >= 1000000:
		t = 1
		break
print(r if t == 1 else -1)


from math import sqrt
(ciudades, poblacion) = input().split()
ciudades = int(ciudades)
poblacion = int(poblacion)
lista = []
for i in range(ciudades):
	(x, y, n) = input().split()
	dist = sqrt(int(x) * int(x) + int(y) * int(y))
	lista.append((dist, int(n)))
lista.sort()
for (d, p) in lista:
	poblacion += int(p)
	if poblacion >= 1000000:
		print(d)
		break
if poblacion < 1000000:
	print(-1)


(n, s) = map(int, input().split())
lst = []
for i in range(n):
	(x, y, z) = map(int, input().split())
	lst.append([(y * y + x * x) ** 0.5, z])
lst.sort()
a = s - 10 ** 6
for i in lst:
	a += i[1]
	if a >= 0:
		exit(print(i[0]))
print(-1)


(n, s) = map(int, input().split())
l = []
for i in range(n):
	(x, y, p) = map(int, input().split())
	l.append(((x * x + y * y) ** 0.5, p))
l.sort()
radius = 0
for i in l:
	radius = i[0]
	s += i[1]
	if s >= int(1000000.0):
		break
if s < int(1000000.0):
	print(-1)
else:
	print('%.7f' % radius)


import math
line = input()
(n, pop) = line.split()
(n, pop) = (int(n), int(pop))
locations = []
for i in range(n):
	line = input()
	locations.append([abs(int(z)) for z in line.split()])
locations.sort(key=lambda x: math.sqrt(x[0] ** 2 + x[1] ** 2))
rad = 0
did_break = False
for i in locations:
	pop = pop + i[2]
	if pop >= 1000000:
		did_break = True
		rad = math.sqrt(i[0] ** 2 + i[1] ** 2)
		print('{0:.7f}'.format(round(rad, 7)))
		break
if did_break == False:
	print(-1)


import sys
import math
import bisect

def query_value(m, dist, population, r):
	n = len(dist)
	ans = m
	for i in range(n):
		if r >= dist[i] - 10 ** (-8):
			ans += population[i]
	return ans

def solve(m, dist, population):
	n = len(dist)
	left = 0
	right = 10 ** 18
	if query_value(m, dist, population, right) < 10 ** 6:
		return -1
	cnt = 128
	while cnt:
		cnt -= 1
		mid = (left + right) / 2
		if query_value(m, dist, population, mid) >= 10 ** 6:
			right = mid
		else:
			left = mid
	return right

def main():
	(n, m) = map(int, input().split())
	dist = []
	population = []
	for i in range(n):
		(x, y, a) = map(int, input().split())
		dist.append(math.sqrt(x ** 2 + y ** 2))
		population.append(a)
	print(solve(m, dist, population))
main()


(n, s) = list(map(int, input().split()))
L = []
for i in range(n):
	(x, y, k) = list(map(int, input().split()))
	L.append((x ** 2 + y ** 2, k))
L.sort()
inc = 0
ind = 0
r = 0
while ind < n and s + inc < 1000000:
	r = L[ind][0]
	inc += L[ind][1]
	ind += 1
if s + inc >= 1000000:
	print(pow(r, 1 / 2))
else:
	print(-1)


from math import sqrt
_Ans = -1
C = []
(n, s) = list(map(int, input().split()))
for i in range(n):
	(x, y, s1) = list(map(int, input().split()))
	C = C + [[sqrt(x * x + y * y), s1]]
if s >= 1000000:
	_Ans = 0
else:
	C.sort()
	i = 0
	while s < 1000000 and i < n:
		_Ans = C[i][0]
		s += C[i][1]
		i += 1
if s >= 1000000:
	print(_Ans)
else:
	print(-1)


import math
(n, s) = map(int, input().split())
locs = []
for _ in range(n):
	(x, y, k) = map(int, input().split())
	d = math.sqrt(x * x + y * y)
	locs[len(locs):] = [(d, k)]
locs.sort()
i = 0
dmin = 0
while i < len(locs) and s < 1000000:
	dmin = locs[i][0]
	s += locs[i][1]
	i += 1
if s < 1000000:
	print(-1)
else:
	print(dmin)


def cmp(town):
	return town[0]
(n, s) = [int(elem) for elem in input().split()]
towns = []
for i in range(n):
	(x, y, p) = [int(elem) for elem in input().split()]
	towns.append(((x ** 2 + y ** 2) ** 0.5, p))
towns.sort(key=cmp)
left = int(1000000.0 - s)
cnt = 0
ans = 0
for (coord, people) in towns:
	cnt += people
	ans = coord
	if cnt >= left:
		break
if cnt >= left:
	print(ans)
else:
	print(-1)


from math import sqrt
(n, s) = map(int, input().split())
arr = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	arr.append([sqrt(x ** 2 + y ** 2), k])
arr = sorted(arr, key=lambda x: x[0])
rad = 0
cnt = 0
while s < 1000000:
	try:
		rad = arr[cnt][0]
		s += arr[cnt][1]
		cnt += 1
	except:
		print(-1)
		exit()
print('{:.7f}'.format(rad))


(n, s) = map(int, input().split())
l = []
for _ in range(n):
	(x, y, k) = map(int, input().split())
	l.append(((x ** 2 + y ** 2) ** 0.5, k))
l.sort()
i = 0
dist = 0
while s < 10 ** 6 and i < n:
	s += l[i][1]
	dist = l[i][0]
	i += 1
if s < 10 ** 6:
	print('-1')
else:
	print('%.7f' % dist)


def distance(x, y):
	return (x * x + y * y) ** 0.5
(n, s) = map(int, input().split())
locations = {}
for i in range(n):
	(x, y, k) = map(int, input().split())
	d = distance(x, y)
	locations[d] = locations.get(d, 0) + k
arr = sorted(locations.items())
ans = -1
for (d, k) in arr:
	if s + k >= 10 ** 6:
		ans = d
		break
	s += k
print(ans)


import math
(n, s) = map(int, input().split(' '))
li = []
for i in range(n):
	(x, y, z) = map(int, input().split(' '))
	li.append([math.sqrt(x ** 2 + y ** 2), z])
li.sort()
ans = 0
an = s
k = 0
while k != n and an < 1000000:
	an += li[k][1]
	ans = li[k][0]
	k += 1
if k == n and an < 1000000:
	print(-1)
else:
	print(ans)


(n, s) = map(int, input().split())
popu = []
su = 0
for i in range(n):
	(a, b, c) = map(int, input().split())
	su += c
	popu.append(((a ** 2 + b ** 2) ** 0.5, -c))
if s + su < 10 ** 6:
	print(-1)
else:
	popu.sort()
	i = 0
	while s < 10 ** 6:
		s += -popu[i][1]
		i += 1
	print(popu[i - 1][0])


def distanciaAlCero(x, y):
	return (x ** 2 + y ** 2) ** 0.5
POBLACION_MINIMA = 1000000
ubicaciones = []
(n, s) = map(int, input().split())
for i in range(n):
	(x, y, k) = map(int, input().split())
	ubicaciones.append((distanciaAlCero(x, y), k))
ubicaciones.sort()
for (distancia, k) in ubicaciones:
	s += k
	if s >= POBLACION_MINIMA:
		print('%.7f' % distancia)
		exit(0)
print(-1)


from math import sqrt

class City:

	def __init__(self, x, y, pop):
		self.distance = sqrt(x * x + y * y)
		self.population = pop
(n, need) = map(int, input().split())
need = 1000000 - need
cities = []
total = 0
for i in range(n):
	(x, y, pop) = map(int, input().split())
	cities.append(City(x, y, pop))
	total += pop
if total < need:
	print(-1)
else:
	cities.sort(key=lambda city: city.distance)
	dis = 0
	i = 0
	while need > 0:
		need -= cities[i].population
		dis = cities[i].distance
		i += 1
	print(dis)


R = lambda : map(int, input().split())
(n, P) = R()
m = {}
for _ in range(n):
	(x, y, p) = R()
	m[x ** 2 + y ** 2] = m.get(x ** 2 + y ** 2, 0) + p
for i in sorted(m.keys()):
	P += m[i]
	if P >= 1000000:
		print(i ** 0.5)
		exit(0)
print(-1)


from math import sqrt
Initialinput = input()
List = Initialinput.split()
Ciudades = []
n = int(List[0])
s = int(List[1])
r = 0
for i in range(0, n):
	Forinput = input()
	location = Forinput.split()
	if len(location) != 3:
		break
	x = int(location[0])
	y = int(location[1])
	r = sqrt(x ** 2 + y ** 2)
	k = int(location[2])
	Ciudades.append([r, k])
Ciudades.sort()
for j in Ciudades:
	k = j[1]
	s = s + k
	if s >= 10 ** 6:
		R = j[0]
		break
if s < 10 ** 6:
	print(-1)
else:
	print(R)


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]
from collections import *
from math import *
(n, s) = inp()
dic = defaultdict(int)
for i in range(n):
	a = arr_inp()
	num = round(sqrt(a[0] ** 2 + a[1] ** 2), 7)
	dic[num] += a[2]
dic2 = OrderedDict(sorted(dic.items(), key=lambda x: x[0]))
for (i, j) in dic2.items():
	s += j
	if s >= 1000000:
		exit(print('{:.7f}'.format(i)))
print(-1)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, s) = f()
s = 1000000 - s
l = []
for _ in range(n):
	(x, y, p) = f()
	l.append([(x ** 2 + y ** 2) ** 0.5, p])
l.sort()
l1 = [0] * (n + 1)
for i in range(1, n + 1):
	l1[i] = l1[i - 1] + l[i - 1][1]
for i in range(1, n + 1):
	if l1[i] >= s:
		exit(print('%0.7f' % l[i - 1][0]))
print(-1)


import math
(num_locations, population_tomsk) = map(int, input().split())
locations = []
for index in range(num_locations):
	(x_i, y_i, k_i) = map(int, input().split())
	distance = x_i ** 2 + y_i ** 2
	locations.append((distance, k_i))
locations.sort(key=lambda x: x[0])
total_population = population_tomsk
radius = -1
for location in locations:
	total_population += location[1]
	if total_population >= 1000000.0:
		radius = location[0]
		break
if radius == -1:
	print(radius)
else:
	print(math.sqrt(radius))


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def calculateUnder(r, a):
	c = 0
	for x in a:
		if sqrt(x[0] ** 2 + x[1] ** 2) <= r:
			c += x[2]
	return c

def b_search(a, need):
	l = 0
	r = 10000
	res = -1
	while l <= r:
		radi = (l + r) / 2
		under = calculateUnder(radi, a)
		if under >= need:
			res = radi
			r = radi - 1e-07
		else:
			l = radi + 1e-07
	return res
(n, p) = invr()
need = 1000000 - p
a = []
for _ in range(n):
	x = inlist()
	d = sqrt(x[0] ** 2 + x[1] ** 2)
	a.append([d, x[2]])
a = sorted(a, key=lambda d: d[0])
tot = 0
for row in a:
	tot += row[1]
	if tot >= need:
		print(row[0])
		sys.exit()
print(-1)


(n, s) = map(int, input().split())
c = []
for i in range(n):
	(x, y, z) = map(int, input().split())
	c.append((x, y, z))
minans = 10 ** 20
for i in range(n):
	nc = 0
	total = s
	for j in range(n):
		if c[j][0] ** 2 + c[j][1] ** 2 <= c[i][0] ** 2 + c[i][1] ** 2:
			total += c[j][2]
	if total >= 10 ** 6 and c[i][0] ** 2 + c[i][1] ** 2 < minans:
		minans = c[i][0] ** 2 + c[i][1] ** 2
if minans != 10 ** 20:
	print(minans ** 0.5)
else:
	print(-1)


from math import sqrt
import sys
(n, m) = map(int, input().split())
d = dict()
for _ in range(n):
	(x, y, z) = map(int, input().split())
	r = round(sqrt(x * x + y * y), 7)
	if r in d:
		d[r] = z + d[r]
	else:
		d[r] = z
d = sorted(d.items(), key=lambda x: x[0])
N = len(d)
dt = 0
for key in d:
	m += key[1]
	if m >= 10 ** 6:
		print(key[0])
		sys.exit()
print(-1)


import sys
import os
t = sys.stdin.readline()
vals = t.split()
neighbors = int(vals[0])
population = int(vals[1])
mega_pop = 1000000.0
tomsk_pop = population
if tomsk_pop >= mega_pop:
	print(0)
table = []
for i in range(neighbors):
	t = sys.stdin.readline()
	vals = t.split()
	x_i = float(vals[0])
	y_i = float(vals[1])
	pop_i = float(vals[2])
	r_i = (x_i ** 2 + y_i ** 2) ** (1 / 2)
	table.append((r_i, pop_i))
table.sort()
for (rad, pop) in table:
	tomsk_pop += pop
	if tomsk_pop >= mega_pop:
		print(rad)
		break
if tomsk_pop < mega_pop:
	print(-1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
from math import *
li = []
(n, s) = map(int, input().split())
s = 1000000 - s
for i in range(n):
	(x, y, add) = map(int, input().split())
	rad = sqrt(x ** 2 + y ** 2)
	li.append((rad, add))
li.sort()
for i in range(n):
	s -= li[i][1]
	if i == n - 1 and s > 0:
		print(-1)
	if s <= 0:
		print('%.7f' % li[i][0])
		break


(n, s) = map(int, input().split())
location = dict()
res = -1
for _ in range(n):
	(x, y, k) = map(int, input().split())
	r = x ** 2 + y ** 2
	if r in location:
		location[r] += k
	else:
		location[r] = k
radius = []
for r in location:
	radius.append(r)
radius.sort()
for r in radius:
	s += location[r]
	if s >= 10 ** 6:
		res = r ** 0.5
		break
print(res)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
arr = [rr() for _ in range(n)]
arr.sort(key=lambda x: x[2])
arr.sort(key=lambda x: sqrt(x[0] ** 2 + x[1] ** 2))
need = 1000000 - k
if sum((k for (i, j, k) in arr)) < need:
	print(-1)
	exit()
m = 0
for (i, j, k) in arr:
	if need <= 0:
		break
	m = max(m, sqrt(i ** 2 + j ** 2))
	need -= k
print(f'{m:.7f}')


import math

def solve():
	(n, population) = map(int, input().split())
	location = dict()
	for i in range(n):
		(x, y, p) = map(int, input().split())
		r = x * x + y * y
		if r in location:
			location[r] += p
		else:
			location[r] = p
	r = []
	for radius in location:
		r.append(radius)
	r.sort()
	for radius in r:
		population += location[radius]
		if population >= 10 ** 6:
			print(math.sqrt(radius))
			return
	print(-1)
solve()


from math import sqrt
(n, s) = input().split()
(n, s) = (int(n), int(s))
coord = [[abs(int(j)) for j in input().split()] for i in range(n)]
rad = [[sqrt(coord[i][0] * coord[i][0] + coord[i][1] * coord[i][1]), coord[i][2]] for i in range(n)]
rad.sort()
b = True
i = 0
while b and i < n:
	s += rad[i][1]
	i += 1
	if s >= 1000000:
		b = False
if b:
	print(-1)
else:
	print(rad[i - 1][0])


class Point:

	def __init__(self, a, b, z):
		self.a = a
		self.b = b
		self.z = z
		self.dist = (a * a + b * b) ** 0.5

def rule(p):
	return p.dist
inf = list(map(int, input().split()))
(n, s) = (inf[0], inf[1])
points = []
for i in range(n):
	inf = list(map(int, input().split()))
	points.append(Point(inf[0], inf[1], inf[2]))
points = sorted(points, key=rule)
ans = 0
i = 0
f = 1
while s < 1000000:
	if i == n:
		f = 0
		print(-1)
		break
	ans = points[i].dist
	s += points[i].z
	i += 1
if f:
	print(ans)


(n, s) = map(int, input().split())
vals = [tuple(map(int, input().split())) for i in range(n)]
vals.sort(key=lambda e: e[0] * e[0] + e[1] * e[1])
b = True
for v in vals:
	s += v[2]
	if s >= 1000000:
		print((v[0] * v[0] + v[1] * v[1]) ** 0.5)
		b = False
		break
if b:
	print(-1)


from math import *
(a, b) = map(int, input().split())
s = sorted(([hypot(i, j), k] for (i, j, k) in (map(int, input().split()) for _ in ' ' * a)))
for i in range(1, a):
	s[i][1] += s[i - 1][1]
lo = 0
hi = a - 1
ans = -1
while lo <= hi:
	mid = (lo + hi) // 2
	if b + s[mid][1] >= 10 ** 6:
		ans = mid
		hi = mid - 1
	else:
		lo = mid + 1
if ans != -1:
	print(s[ans][0])
else:
	print(-1)


from collections import Counter

def main():
	(n, s) = map(int, input().split())
	cities = []
	for _ in range(n):
		(x, y, k) = map(int, input().split())
		dist = x * x + y * y
		cities.append((dist, k))
	cities.sort()
	cnt = Counter()
	cnt[0] = s
	for (dist, k) in cities:
		cnt[dist] += k
	_sum = 0
	for (k, v) in cnt.items():
		_sum += v
		if _sum >= 1000000:
			print(k ** 0.5)
			return
	print(-1)
main()


import math
import sys
(n, p) = map(int, input().split())
cities = []
for i in range(n):
	(x, y, pi) = map(int, input().split())
	cities.append(((x, y), pi))
sorted_cities = sorted(cities, key=lambda data: math.sqrt(data[0][0] ** 2 + data[0][1] ** 2))
for i in range(n):
	if p < 1000000:
		p += sorted_cities[i][1]
		if p >= 1000000:
			print(math.sqrt(sorted_cities[i][0][0] ** 2 + sorted_cities[i][0][1] ** 2))
			sys.exit()
print(-1)


(n, s) = map(int, input().split())
d = dict()
for _ in range(n):
	(x, y, k) = map(int, input().split())
	r = (x * x + y * y) ** 0.5
	if r not in d:
		d[r] = k
	else:
		d[r] += k
for (r, v) in sorted(d.items()):
	s += v
	if s >= 10 ** 6:
		print(round(r, 7))
		exit(0)
print(-1)


from itertools import *
from math import hypot
MEGANUM = 10 ** 6

def read_ints():
	return map(int, input().strip().split())
(n, s) = read_ints()
cities = [read_ints() for _ in range(n)]
bydist = []
for city in cities:
	(x, y, k) = city
	dist = hypot(x, y)
	bydist.append((dist, k))
bydist.sort()
mindist = 0
is_mega = False
for cit in bydist:
	(dist, k) = cit
	mindist = dist
	s += k
	if s >= MEGANUM:
		is_mega = True
		break
if is_mega:
	print(mindist)
else:
	print(-1)


from math import sqrt

def dist(x, y):
	return sqrt(x * x + y * y)

def main():
	(n, s) = map(int, input().split())
	m = {}
	for i in range(n):
		(x, y, k) = map(int, input().split())
		d = dist(x, y)
		if d not in m:
			m[d] = k
		else:
			m[d] += k
	ans = -1
	for i in sorted(m):
		s += m[i]
		if s >= 1000000:
			ans = i
			break
	print(-1 if ans == -1 else ans)
main()


import math

class Node:

	def __init__(self, key=0):
		self.key = key
		self.left = None
		self.right = None

def insertNode(root, x):
	global best
	if root == None:
		return Node(x)
	if x < root.key:
		root.left = insertNode(root.left, x)
		best = max(root.key - x, best)
	elif x > root.key:
		root.right = insertNode(root.right, x)
	return root
(n, pop) = map(int, input().split())
city = dict()
for _ in range(n):
	(x, y, p) = map(int, input().split())
	radius = math.sqrt(x ** 2 + y ** 2)
	city[radius] = city.get(radius, 0) + p
need = 1000000 - pop
ar = sorted(list(city.keys()))
for i in ar:
	need -= city[i]
	if need <= 0:
		print(i)
		quit()
print(-1)


import math
(n, s) = map(int, input().split())
population = s
arr = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	ans = math.pow(x, 2) + math.pow(y, 2)
	s += k
	arr += [(ans, k)]
if s < 10 ** 6:
	print(-1)
arr.sort()
for i in range(n):
	population += arr[i][1]
	if population >= 10 ** 6:
		print(math.sqrt(arr[i][0]))
		break


from math import sqrt
(n, curr) = [int(p) for p in input().split()]
neigh = []
for i in range(n):
	neigh.append([int(p) for p in input().split()])
neigh.sort(key=lambda x: x[0] ** 2 + x[1] ** 2)
i = 0
r = 0
while curr < 10 ** 6 and i < len(neigh):
	(x, y, p) = neigh[i]
	r = max(r, sqrt(x ** 2 + y ** 2))
	curr += p
	i += 1
if curr >= 10 ** 6:
	print(r)
else:
	print(-1)


import sys
import math

def dist2origin(x, y):
	return x ** 2 + y ** 2

def megacity(n, s, locations):
	population = s
	distances = []
	for loc in locations:
		distances.append(math.sqrt(loc[0] ** 2 + loc[1] ** 2))
		population += loc[2]
	if population < 1000000:
		return -1
	else:
		inds = sorted(range(n), key=lambda k: distances[k])
		min_radius = 0.0
		population = s
		ind = 0
		while population < 1000000:
			min_radius = distances[inds[ind]]
			population += locations[inds[ind]][2]
			ind += 1
		return min_radius
for line in sys.stdin:
	n_s = [int(val) for val in line.split()]
	(n, s) = (n_s[0], n_s[1])
	locations = []
	for i in range(n):
		location = [int(val) for val in sys.stdin.readline().split()]
		locations.append(location)
	answer = megacity(n, s, locations)
	print(answer)


(n, p) = map(int, input().split())
dic = {}
for i in range(n):
	(x, y, t) = map(int, input().split())
	dist = (x ** 2 + y ** 2) ** 0.5
	if dist in dic.keys():
		dic[dist] = dic[dist] + t
	else:
		dic[dist] = t
for j in sorted(dic):
	p = p + dic[j]
	if p >= 1000000:
		print(j)
		break
else:
	print(-1)


localidades = []
(n, poblacion) = input().split()
n = int(n)
poblacion = int(poblacion)
for i in range(n):
	(a, b, gente) = input().split()
	a = int(a)
	b = int(b)
	gente = int(gente)
	localidades.append(((a ** 2 + b ** 2) ** 0.5, gente))
localidades.sort()
r = 0
for (radio, m) in localidades:
	if poblacion < 1000000:
		poblacion += m
		r = radio
	else:
		break
if poblacion < 1000000:
	print(-1)
else:
	print(r)


def main():
	(n, s) = map(int, input().split())
	cities = []
	for i in range(n):
		(x, y, p) = map(int, input().split())
		dist = (x ** 2 + y ** 2) ** (1 / 2)
		cities.append((x, y, p, dist))
		cities.sort(key=lambda city: city[3])
	total = s
	for city in cities:
		total += city[2]
		if total >= 10 ** 6:
			print((city[0] ** 2 + city[1] ** 2) ** (1 / 2))
			return
	print(-1)
main()


(n, s) = map(int, input().split())
a = []
c = 0
for i in range(n):
	(x, y, k) = map(int, input().split())
	c += k
	a += [(x, y, k)]
if s + c < 1000000:
	print(-1)
else:
	a.sort(key=lambda x: (abs(x[0] * x[0]) + abs(x[1] * x[1])) ** 0.5)
	ans1 = 0
	ans2 = 0
	for i in range(n):
		s += a[i][2]
		if s >= 1000000:
			ans1 = a[i][0]
			ans2 = a[i][1]
			break
	print((abs(ans1 * ans1) + abs(ans2 * ans2)) ** 0.5)


INF = int(10000000000.0)
import math

def int_input():
	return int(input().strip())

def list_int_input():
	return [int(i) for i in input().strip().split(' ')]

def dist_from_root(x, y):
	return math.sqrt(x * x + y * y)

class City(object):

	def __init__(self, x, y, pop):
		self.x = x
		self.y = y
		self.pop = pop

	def dist_from_root(self):
		return dist_from_root(self.x, self.y)

	def __lt__(self, other):
		return dist_from_root(self.x, self.y) < dist_from_root(other.x, other.y)

	def __repr__(self):
		return '{}: {}|{}: {}'.format(dist_from_root(self.x, self.y), self.x, self.y, self.pop)

def read_input():
	(n, s) = list_int_input()
	cities = []
	for _ in range(n):
		(x, y, k) = list_int_input()
		cities.append(City(x, y, k))
	return (cities, s)

def main():
	(cities, s) = read_input()
	cities.sort()
	total_pop = s
	i = 0
	while total_pop < int(1000000.0) and i < len(cities):
		c = cities[i]
		if i < len(cities) - 1 and cities[i + 1].dist_from_root() == c.dist_from_root():
			while i < len(cities) - 1 and cities[i + 1].dist_from_root() == c.dist_from_root():
				total_pop += c.pop
				i += 1
				c = cities[i]
		else:
			total_pop += c.pop
			i += 1
	if total_pop < int(1000000.0):
		print('-1')
		return
	c = cities[i - 1]
	print(c.dist_from_root())
main()


(n, pop) = [int(j) for j in input().split()]
(dist, pops) = ([], [])

def mergesort(l, r):
	size = r - l
	if size < 2:
		return
	mid = int(size / 2) + l
	mergesort(l, mid)
	mergesort(mid, r)
	(d_dist, d_pops) = ([], [])
	(p1, p2) = (l, mid)
	while p1 < mid and p2 < r:
		if dist[p1] < dist[p2]:
			d_dist.append(dist[p1])
			d_pops.append(pops[p1])
			p1 += 1
		else:
			d_dist.append(dist[p2])
			d_pops.append(pops[p2])
			p2 += 1
	while p1 < mid:
		d_dist.append(dist[p1])
		d_pops.append(pops[p1])
		p1 += 1
	while p2 < r:
		d_dist.append(dist[p2])
		d_pops.append(pops[p2])
		p2 += 1
	for j in range(l, r):
		dist[j] = d_dist[j - l]
		pops[j] = d_pops[j - l]
for j in range(n):
	(x, y, p) = [int(j) for j in input().split()]
	d = x * x + y * y
	d = pow(d, 0.5)
	dist.append(d)
	pops.append(p)
mergesort(0, n)
(radius, pointer) = (0, 0)
while pop < 1000000 and pointer < n:
	radius = dist[pointer]
	pop += pops[pointer]
	pointer += 1
if pop >= 1000000:
	print(radius)
else:
	print(-1)


(n, k) = map(int, input().split())
if k >= 1000000:
	print('0')
	return

def f():
	(x, y, d) = map(int, input().split())
	return (x * x + y * y, d)
t = [f() for i in range(n)]
t.sort()
for (r, d) in t:
	k += d
	if k >= 1000000:
		print(r ** 0.5)
		break
else:
	print('-1')


from math import sqrt
(n, s) = map(int, input().split())
l = []
for i in range(n):
	(x, y, k) = map(int, input().split())
	d = sqrt(x ** 2 + y ** 2)
	l.append([d, k])
l.sort()
i = 0
k = 0
g = 10 ** 6
while i < n and s + k < g:
	k += l[i][1]
	i += 1
if k + s < g:
	print(-1)
else:
	print(round(l[i - 1][0], 7))


import sys
import math
texto = sys.stdin.read().split('\n')
texto.pop(-1)
contador = 0
poblacion = 0
radio = 0
lugares = []
for linea in texto:
	if contador == 0:
		poblacion = int(linea.split(' ')[1])
		radio = int(linea.split(' ')[0])
	else:
		lugares += [[int(x) for x in linea.split(' ')]]
	contador += 1
lugares.sort(key=lambda x: x[0] ** 2 + x[1] ** 2)
for lugar in lugares:
	poblacion += lugar[2]
	if poblacion >= 1000000:
		print((lugar[0] ** 2.0 + lugar[1] ** 2.0) ** (1 / 2))
		break
if poblacion < 1000000:
	print(-1)


from math import pi, sqrt
(n, s) = map(int, input().rstrip().split())
arr = []
for _ in range(n):
	line = list(map(int, input().rstrip().split()))
	arr.append([sqrt(line[0] ** 2 + line[1] ** 2), line[2]])
arr.sort(key=lambda x: x[0])
flag = False
for e in arr:
	s += e[1]
	if s >= 1000000:
		print('{0:.7f}'.format(e[0]))
		flag = True
		break
if flag == False:
	print(-1)


import re
import inspect
from sys import argv, exit

def rstr():
	return input()

def rint():
	return int(input())

def rints(splitchar=' '):
	return [int(i) for i in input().split(splitchar)]

def varnames(obj, namespace=globals()):
	return [name for name in namespace if namespace[name] is obj]

def pvar(var, override=False):
	prnt(varnames(var), var)

def prnt(*args, override=False):
	if '-v' in argv or override:
		print(*args)

class City:

	def __init__(self, x, y, pop):
		self.x = x
		self.y = y
		self.pop = pop
		self.dist = (x ** 2 + y ** 2) ** (1 / 2)

	def __str__(self):
		return '|{}, {}, {}, {:.2f}|'.format(self.x, self.y, self.pop, self.dist)

	def __repr__(self):
		return str(self)
(n, pop) = rints()
target = 1000000
cities = sorted([City(*rints()) for i in range(n)], key=lambda c: c.dist)
prnt(cities)
r = 0
for city in cities:
	if pop >= target:
		break
	else:
		r = city.dist
		pop += city.pop
if pop >= target:
	print(r)
else:
	print(-1)


import math

def solve():
	(n, s) = map(int, input().split())
	location = []
	for i in range(n):
		(x, y, k) = map(int, input().split())
		location += [(x * x + y * y, k)]
	location.sort()
	for i in range(n):
		s += location[i][1]
		if s >= 1000000:
			print(math.sqrt(location[i][0]))
			exit()
	print(-1)
solve()


(n, s) = map(int, input().split())
ml = []

def dis(x, y):
	return (x ** 2 + y ** 2) ** 0.5
for _ in range(n):
	(x, y, i) = map(int, input().split())
	ml.append([dis(x, y), i])
ml.sort()
r = 0
i = 0
while i < n and s < 10 ** 6:
	s += ml[i][1]
	r = ml[i][0]
	i += 1
if s >= 10 ** 6:
	print(r)
else:
	print(-1)


(n, s) = map(int, input().split())
d = dict()
for i in range(n):
	(x, y, s_i) = map(int, input().split())
	r_i = (x ** 2 + y ** 2) ** 0.5
	if r_i not in d:
		d[r_i] = s_i
	else:
		d[r_i] += s_i
keys = sorted(d)
result = s
r_res = -1
for r in keys:
	result += d[r]
	if result >= 1000000.0:
		r_res = r
		break
print(r_res)


import sys
import math
(n, s) = list(map(int, input().split()))
a = []
for x in range(n):
	(x, y, k) = list(map(int, input().split()))
	r = math.sqrt(x ** 2 + y ** 2)
	a.append((r, k))
a = sorted(a)
for i in range(n):
	if s < 1000000:
		s += a[i][1]
	else:
		print(a[i - 1][0])
		sys.exit()
if s >= 1000000:
	print(a[-1][0])
else:
	print(-1)


(n, s) = map(int, input().split())
d = dict()
for i in range(n):
	(x, y, p) = map(int, input().split())
	distance = round((x ** 2 + y ** 2) ** (1 / 2), 7)
	if distance not in d:
		d[distance] = p
	else:
		d[distance] = d[distance] + p
radius = 0
lst = list(d.items())
lst.sort()
population = s
for i in range(len(lst)):
	radius = lst[i][0]
	population = population + lst[i][1]
	if population >= 1000000:
		print(radius)
		break
if population < 1000000:
	print(-1)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
(a, b) = mul()
k = []
summ = b + 0
for _ in range(a):
	(x, y, z) = mul()
	k.append([math.sqrt(x ** 2 + y ** 2), x, y, z])
	summ += z
if summ <= 10 ** 6:
	print(-1)
	exit()
k.sort()
for i in k:
	if b + i[3] >= 10 ** 6:
		print(i[0])
		break
	else:
		b += i[3]


(n, p) = map(int, input().split())
l = []
for i in range(n):
	(x, y, pp) = map(int, input().split())
	l.append(((x * x + y * y) ** 0.5, pp))
l.sort()
chosen = -1
done = False
if p >= 1000000:
	chosen = 0
for (dist, pp) in l:
	p += pp
	if p >= 1000000:
		chosen = dist
		break
print(round(chosen, 7))


import math
(n, s) = [int(x) for x in input().split()]
l = []
s1 = s
for i in range(n):
	l.append([int(x) for x in input().split()])
	s += l[i][2]
if s < 1000000:
	print(-1)
else:
	d = {}
	l1 = []
	for i in range(len(l)):
		x = l[i][0]
		y = l[i][1]
		val = math.sqrt(pow(x, 2) + pow(y, 2))
		l1.append([val, l[i][2]])
	l1.sort()
	ans = 0
	sm = s1
	for i in range(len(l1)):
		if sm >= 1000000:
			break
		sm += l1[i][1]
		ans = l1[i][0]
	print('%.7f' % ans)


import cmath

def sorted_list(x):
	return x[3]
str = input().split()
n = int(str[0])
s = int(str[1])
r = 0
x = [0] * n
for i in range(n):
	x[i] = [0] * 4
	str = input().split()
	for (j, item) in enumerate(str):
		x[i][j] = int(item)
	x[i][3] = round((x[i][1] ** 2 + x[i][0] ** 2) ** 0.5, 7)
x.sort(key=sorted_list)
for item in x:
	if s < 1000000:
		r = item[3]
		s += item[2]
if s < 1000000:
	print(-1)
else:
	print(r)


from math import *
(n, s) = map(int, input().split())
dist = []
for i in range(n):
	(a, b, c) = map(int, input().split())
	dist.append((a * a + b * b, c))
dist = sorted(dist)
i = 0
while s < 1000000 and i < n:
	s += dist[i][1]
	i += 1
if s < 1000000:
	print(-1)
elif i == 0:
	print(0)
else:
	print(sqrt(dist[i - 1][0]))


import math
(n, s) = map(int, input().split())
lis = []
for i in range(n):
	(a, b, c) = map(int, input().split())
	r = math.sqrt(a * a + b * b)
	lis.append([r, c])
lis.sort()
for i in range(n):
	s += lis[i][1]
	if s >= 1000000:
		print(lis[i][0])
		exit()
print('-1')


import math

def get_ans():
	(n, s) = map(int, input().split())
	l = []
	for _ in range(n):
		(x, y, k) = map(int, input().split())
		l.append((x ** 2 + y ** 2, x, y, k))
	l.sort()
	m = 10 ** 6
	pos = 0
	if s >= m:
		return pos
	for (idx, i) in enumerate(l):
		s += i[3]
		if s >= m:
			return math.sqrt(i[0])
	if s < m:
		return -1
ans = get_ans()
print(ans)


import math
(n, s) = map(int, input().split())
city = {}
for i in range(n):
	(x, y, p) = map(int, input().split())
	city[x ** 2 + y ** 2] = city.get(x ** 2 + y ** 2, 0) + p
res = 0
for (key, value) in sorted(city.items(), key=lambda x: x[0]):
	s += value
	if s >= 1000000:
		res = key
		break
if s < 1000000:
	print('-1')
else:
	print(math.sqrt(res))


import sys
import math
sys.setrecursionlimit(100000)

class Pair:

	def __init__(self, x, y):
		self.first = x
		self.second = y

def EuclidDist(x, y):
	return pow(x * x + y * y, 1 / 2)
(n, s) = map(int, input().split())
M = dict()
for i in range(n):
	(x, y, p) = map(int, input().split())
	r = EuclidDist(x, y)
	if r in M:
		M[r] += p
	else:
		M[r] = p
lst = []
for (key, value) in zip(M.keys(), M.values()):
	lst.append(Pair(key, value))
lst.sort(key=lambda x: x.first)
for point in lst:
	s += point.second
	if s >= int(1000000.0):
		print('{:.7f}'.format(point.first))
		raise SystemExit
print(-1)


from math import *
R = lambda : map(int, input().split())
(n, s) = R()
x = sorted(((x * x + y * y, k) for (x, y, k) in (R() for i in range(n))))
for i in range(n):
	s += x[i][1]
	if s >= 1000000:
		print(sqrt(x[i][0]))
		return
print(-1)