题解 | 圆覆盖-java

圆覆盖

https://www.nowcoder.com/practice/4f96afe5dfe74dad88dbe419d33f9536

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long m=sc.nextLong();
        long[][]ve=new long[n][2];
        for (int i = 0; i < n; i++) {
            long x=sc.nextLong();
            long y=sc.nextLong();
            long v=sc.nextLong();
            ve[i][0]=x*x+y*y;
            ve[i][1]=v;
        }   
        Arrays.sort(ve,(a,b)->Long.compare(a[0], b[0]));
        long sum=0;
        boolean flag=false;
        for (int i = 0; i < n; i++) {
            sum+=ve[i][1];
            if(sum>=m){
                System.out.println(Math.sqrt(ve[i][0]));
                flag=true;
                break;
            }
        }
    if(!flag){
        System.out.println(-1);
    }
        sc.close();
    }
}

#java##java转测开#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务