把小时乘60加上分钟,化成一个整数便于比较:

import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] v = new int[N];
        for(int i = 0; i < N; ++i){
            v[i] = sc.nextInt()*60 + sc.nextInt();    //把小时乘60加上分钟,化成一个整数便于比较
        }
        int go = sc.nextInt();
        int school = sc.nextInt()*60 + sc.nextInt();
        Arrays.sort(v);
        for(int i = v.length - 1; i >= 0; --i){
            if(v[i] + go <= school){
                System.out.printf("%d %d", v[i]/60, v[i]%60);    //再化回去
                return;
            }
        }
    }
}