求助!70分,有三个测试点显示爆内存
查看原帖
求助!70分,有三个测试点显示爆内存
1367241
zzzccc111楼主2025/1/25 10:47

怎么回事呢


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
      
        int[][] matches = new int[n][2];

        for (int i = 0; i < n; i++) {
            matches[i][0] = scanner.nextInt(); // 开始时间
            matches[i][1] = scanner.nextInt(); // 结束时间
        }

        // 按照比赛结束时间升序排序
        Arrays.sort(matches, (a, b) -> a[1] - b[1]);
    
        int finish = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (finish <= matches[i][0]) {
                ans++;
                finish = matches[i][1];
            }
        }

        System.out.println(ans);
    }
}

2025/1/25 10:47
加载中...