万如意


私信TA

用户名:uq_96396066809

访问量:15387

签 名:

等  级
排  名 152
经  验 7055
参赛次数 0
文章发表 74
年  龄 18
在职情况 学生
学  校 湖北生物科技职业学院
专  业 计算机应用

  自我简介:

TA的其他文章

寻找矩阵最值
浏览:224

解题思路:

注意事项:

参考代码:

import java.awt.print.Book;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();//接收几组数据
		for (int i = 0; i < m; i++) {
			int n = sc.nextInt();//小朋友数量
			int[][] arr = new int[n][2];//小朋友有的积木数和他一共需要的积木数
			for (int j = 0; j < n; j++) {
				arr[j][0] = sc.nextInt();
				arr[j][1] = sc.nextInt();
			}
			Arrays.sort(arr,new Comparator<int[]>(){
				public int compare(int[]o1,int[]o2) {
					return (o1[1]-o1[0])-(o2[1]-o2[0])>0?1:-1;
				}
			});
			int num = 0;
			boolean f = true;//假设玩的下去
			for (int j = 0; j < n; j++) {
				//当前小朋友已有的积木数量+积木池的数量>需要的数量
				if (arr[j][0]+num>=arr[j][1]) {
					num+=arr[j][0];
				}
				else {
					f = false;
					break;
				}
			}
			if (f == true) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
	}


}


 

0.0分

5 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区