才发现我没sort。。。服了,题目没说闹钟有顺序,这样竟然也过了80.。。。,一下是刚才在牛客网上AC的
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while ( sc.hasNextLong() ) {
            int n = sc.nextInt();
            int[] times = new int[n];
            for (int i = 0; i < n; i++) {
                int h = sc.nextInt() * 60;
                int m = sc.nextInt();
                times[i] = h + m;
            }
            Arrays.sort(times);
            int cost = sc.nextInt();
            int sh = sc.nextInt() * 60;
            int sm = sc.nextInt();
            int target = sh + sm;
            int left = target - cost;
            int res = -1;
            for (int i = 0; i < n; i++) {
                if (left == times[i]) {
                    res = left;
                    break;
                }
            }
            for (int i = 1; i < n; i++) {
                if (left > times[i - 1] && left < times[i]) {
                    res = times[i - 1];
                    break;
                }
            }
            int hour = res / 60;
            int min = res % 60;
            System.out.println(hour + " " + min);
        }
    }
}