Niu Niu always overslept, so he set a lot of alarms, only when the alarm went off would he wake up and decide not to get up. It takes X minutes for him to get to the classroom from the time he wakes up. The class time is at A hour and B minutes of the day. What time can he get up at the latest?
Enter description:
Each input contains a test case.
The first line of each test case contains a positive integer representing the number N of alarms (N<=100).
The next N lines each contain two integers, indicating that the alarm clock sounded at Mi (0<=B<60) minutes when Hi(0<=A<24).
The next line contains an integer indicating that he needs X (0<=X<=100) minutes to reach the classroom from the time he wakes up.
The next line contains two integers, indicating that the class time is A (0<=A<24) and B (0<=B<60) minutes.
The data guarantees that at least one alarm clock will get Niu Niu to the classroom in time.
Output description:
Output two integers to indicate the latest wake-up time for Niu Niu.
Input example 1:
3 5 0 6 0 7 0 59 6 59
Output example 1:
6 0
#include <iostream> using namespace std; intmain() { int N, h1, m1,h2, m2, x, goclass; int res = 0; cin >> N; int getup[N]; for (int i = 0; i < N; i++) { cin >> h1 >> m1; getup[i] = h1 * 60 + m1; } cin >> x >> h2 >> m2; goclass = h2 * 60 + m2; for (int i = 0; i < N; i++) { if (getup[i] + x <= goclass && getup[i] > res) res = getup[i]; } cout << res / 60 << ' ' << res % 60; return 0; }