Basketball Lead Time

Interview

Time limit1sMemory limit128 MB

Summary
Given timestamped scoring events over a 48 minute game, compute the total time each team held the lead.
Level

Medium4 of 10

Topics
Simulation, Sorting, Implementation
Solved
No attempts yet

Problem

Donghyuk has the scoring log for a basketball game that lasts exactly 48 minutes. Each record tells which team scored and the time of the score.

Given the scoring records for the two teams, find the total amount of time that team 1 and team 2 were each ahead during the game. Time while the score is tied does not count for either team.

Input

The first line contains the number of scores N. (1 <= N <= 100)

Each of the next N lines contains one scoring record in the form team time. The team number is 1 or 2, and the time is written as MM:SS. The minute is between 0 and 47, and the second is between 0 and 59. One-digit values are written with a leading 0, and no two scores occur at the same time.

Output

Print the total time that team 1 was ahead on the first line, and the total time that team 2 was ahead on the second line. Use the MM:SS format.

Examples3

  1. Example 1

    Input
    1
    1 20:00
    
    Expected output
    28:00
    00:00
    
  2. Example 2

    Input
    3
    1 01:10
    2 21:10
    2 31:30
    
    Expected output
    20:00
    16:30
    
  3. Example 3

    Input
    5
    1 01:10
    1 02:20
    2 45:30
    2 46:40
    2 47:50
    
    Expected output
    45:30
    00:10