- 제목
Everyone Loves to Sleep
- 조건
time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output
- 문제
Vlad, like everyone else, loves to sleep very much.
Every day Vlad has to do nn things, each at a certain time. For each of these things, he has an alarm clock set, the i-th of them is triggered on hi hours mi minutes every day (0≤hi<24,0≤mi<60). Vlad uses the 24-hour time format, so after h=12,m=59 comes h=13,m=0 and after h=23,m=59 comes h=0,m=0.
This time Vlad went to bed at H hours M minutes (0≤H<24,0≤M<60) and asks you to answer: how much he will be able to sleep until the next alarm clock.
If any alarm clock rings at the time when he went to bed, then he will sleep for a period of time of length 0.
- 입력
The first line of input data contains an integer t (1≤t≤100) — the number of test cases in the test.
The first line of the case contains three integers n, H and M (1≤n≤10,0≤H<24,0≤M<60) — the number of alarms and the time Vlad went to bed.
The following n lines contain two numbers each hi and mi (0≤hi<24,0≤mi<60) — the time of the i alarm. It is acceptable that two or more alarms will trigger at the same time.
Numbers describing time do not contain leading zeros.
- 출력
t lines, each containing the answer to the corresponding test case. As an answer, output two numbers — the number of hours and minutes that Vlad will sleep, respectively. If any alarm clock rings at the time when he went to bed, the answer will be 0 0.
예제 입력 1 | 3 1 6 13 8 0 3 6 0 12 30 14 45 6 0 2 23 35 20 15 10 30 |
예제 출력 1 | 1 47 0 0 10 55 |
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc, N, h, m, sum;
int th, tm, tsum, min_sum;
cin >> tc;
while(tc--){
cin >> N >> h >> m;
sum = h * 60 + m;
min_sum = 987654321;
for(int n = 0; n < N; n++){
cin >> th >> tm;
if(min_sum == 0) continue;
if(th == h && tm == m){
min_sum = 0;
continue;
}
tsum = th * 60 + tm;
if(tsum < sum) tsum += 24 * 60;
min_sum = min(min_sum, tsum - sum);
}
min_sum %= 24 * 60;
th = min_sum / 60;
tm = min_sum % 60;
cout <<th << ' ' << tm << endl;
}
return 0;
}