难点1:接受所有点的输入,并按照权值排序

按照第二次练习提到的,在“set型列表”中使用sort方法,可以很方便地对多维数据进行排序。

难点2:数学计算与格式化输出

导入math库即可。


import math

n, k = map(int, input().split())
points = []
total_weight = 0
for _ in range(n):
  x, y, w = map(int, input().split())
  dist_sq = x * x + y * y
  points.append((dist_sq, w))
  total_weight += w

  if total_weight < k:
    print(-1)
    return

  points.sort()

  current_weight = 0
  min_dist_sq = 0

  for dist_sq, weight in points:
    current_weight += weight
    if current_weight >= k:
      min_dist_sq = dist_sq
      break

print(f"{(math.ceil(math.sqrt(min_dist_sq)*1000000))/1000000:.6f}")