John is going back home after a party. Currently he is standing on a bus station and waiting for a bus to arrive. There is a timetable of arriving buses near the station. Beside this, John also knows the amount of time that is needed to travel with specific bus. As he has only one ticket, there are no possibilities to change the bus somewhere in the middle of a trip in order to make it shorter. Can you help John to calculate minimal time that he needs to get home?
INPUT
There is a number of tests T
(T ≤ 100) on the first line. Each test case contains the number of buses K
(1 ≤ K ≤ 100) and current time (in format HH:MM
). Each of the next K lines contain arrival time of the bus (in the same format as current time) and travelling time 0 ≤ Q ≤ 1000 needed for John to get home (in minutes). Refer to the sample input as an example.
OUTPUT
For each test case output a single line "Case T: N"
. Where T
is the test case number (starting from 1) and N
minimal time (in minutes) needed for John to go back home.
SAMPLE INPUT
2 1 18:00 19:30 30 2 18:00 19:00 100 20:00 30
SAMPLE OUTPUT
Case 1: 120 Case 2: 150刚开始把汽车到达时间早于当前时间的过滤掉了,提交Wrong Answer
#include <cstdio>
#include <climits>
using namespace std;
const int N = 110;
const int DAY = 24 * 60;
struct Bus
{
int arriveTime, travelTime;
};
Bus bus[N];
int n, curTime;
bool input();
int solve();
int main()
{
#ifndef ONLINE_JUDGE
freopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endif
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++) {
input();
printf("Case %d: %d\n", i, solve());
}
return 0;
}
bool input()
{
int h, m;
scanf("%d %d:%d", &n, &h, &m);
curTime = h * 60 + m;
for (int i = 0; i < n; i++) {
scanf("%d:%d %d", &h, &m, &bus[i].travelTime);
bus[i].arriveTime = h * 60 + m;
}
return true;
}
int solve()
{
int ans = INT_MAX;
for (int i = 0; i < n; i++) {
if (curTime > bus[i].arriveTime) {
bus[i].arriveTime += DAY;
}
int cost = bus[i].arriveTime - curTime + bus[i].travelTime;
if (cost < ans) ans = cost;
}
return ans;
}