UCV2013G - Schedules

no tags 

PEPE the singer has released a new song. He wants to control how many times his songs is played on RUMBA FM radio station. PEPE has hired two companies (A and B) to perform this task. Every day, they give him a schedule indicating the time when the song has been played on the radio. Song always takes the same number of seconds to play, so end times are not important. We are only interested in start times.

On the first day PEPE received both schedules. They were almost identical. He verified that each entry of A corresponds to exactly one entry in B. He simply took a pencil, and he marked one entry in A, and then the corresponding entry in B. He continued with this approach as long as unmarked entries exist. The second day PEPE again received both schedules, but he found that the number of entries in both schedules is not the same. Moreover, the times did not match at all due to a human error. He said, "Oh Gosh!, I have to reconcile both schedules, finding the best possible match between them". He only trusts the entries that can be matched in both schedules. But how to match them? PEPE started by deciding how many seconds of error (difference) he is able to tolerate for two matched entries. Then he tried to find the largest number of possible matches. For equally large matchings, he is interested in smallest average time difference in seconds. Unfortunately, it may take too long since his new song are very popular, having many hits in RUMBA FM. So, we need your help to perform this task automatically.

Input

The input consists in several test cases. Each test case starts with a line containing three integer numbers Na, Nb, and S, separated by single spaces. Na and Nb are the number of entries in A and B respectively (1 <= Na, Nb <= 200), and S is the tolerance in seconds (0 <= S <= 7200). The second line contains Na time stamps in the format hh:mm:ss separated by single spaces. The third line contains Nb time stamps in same format as the previous one. Note that all start times are in the same day.

The end of the input is an empty test case, where Na = Nb = S = 0 and should not be processed.

Output

For each test case, the output is a single line containing an integer K and floating point number V rounder to one decimal place. K is the largest number of matches between schedule A and schedule B. V is the average time difference in seconds between the K matched entries. In case there is no possible match, your program should instead print "No matches"

Example

Input:
4 2 120
03:00:00 03:00:59 07:40:00 12:40:04
02:59:14 12:41:45
3 2 60
03:00:59 07:40:00 12:40:04
02:59:14 12:41:45
0 0 0 Output: 2 73.5
No matches

hide comments
Mitch Schwartz: 2013-07-26 16:21:19

I think my handle on English is ok, but after reading the problem a few times I don't even know what it's asking. I guess we are simply matching the time stamps such that for each pair (a,b) with a in A and b in B, abs(a-b) <= tolerance? So we don't have to care about song durations? Is the absolute difference between 23:59:59 and 00:00:00 considered 1 second? Can we get an upper limit on the number of test cases to get a better idea of what complexity solution is expected? Please respond, or the problem may be hidden.

Edit: Thanks for the reply.

Last edit: 2013-07-26 20:23:22
Hector Navarro: 2013-07-25 15:47:57

@Pranay: It fails on a lot of cases

Hector Navarro: 2013-07-25 15:45:53

@Hasil: You cannot match 02:59:14 with both 03:00:00 and 03:00:59. You have to pick one

Pranay: 2013-07-25 06:40:24

cant get why WA? 9715808

Hasil Sharma: 2013-07-25 05:23:49

for the first test case :
03:00:00 - 02:59:14 = 46
03:00:59 - 02:59:14 = 105
12:40:04 - 12:41:45 = 101
ans should be 3 84.0 , right ?


Added by:Hector Navarro
Date:2013-07-22
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Local UCV 2013. Rhadamés Carmona