BNKQ

Time limit2sMemory limit512 MB

Summary
From a day of bank teller queue records, find each teller's processed-customer count and busiest one-hour window, then report the top three tellers.
Level

Medium5 of 10

Topics
Hash map, Sorting, Implementation, Prefix sum
Solved
No attempts yet

Problem

Nili bank provides banking services to customers throughout the country. Each of its branches has several tellers who handle deposits and withdrawals for customers. Each teller has a queue of customers waiting to deposit or withdraw money through that teller. The bank records the customer, the time the customer stood in the queue (or was processed), and the teller.

With these records, the bank wants to know which tellers were busiest and what their peak time frame during the day was.

Write a program that reads the records for a single day and prints the three busiest tellers and their peak time frames.

Input

The first N lines (N < 10000) contain the records for a single day.

  • Record format: TELLERCUSTOMER[TIME]
  • TELLER is the teller id
  • CUSTOMER is the customer id
  • TIME is the time (between 08:00:00AM and 04:00:00PM) the customer stood in the queue or was processed by the teller
  • The first occurrence of a record is when the customer stands in the queue; the second occurrence of the same record is when the customer is processed
  • [TIME] is absent from the record if the customer leaves the queue without being processed. The input ends with the line ENDOFINPUT, which is not part of the input.

Output

Print the three busiest tellers, the total number of customers each processed in the day, and each one's peak time frame (in hours), one teller per line.

  • Format: TELLERPROCESSED-COUNTPEAK-TIMEFRAME

  • A busy teller is one who processes more customers, not one who has more customers in the queue.

  • If there are multiple time frames with the same peak weight, print the first peak time frame (the one nearest to 08:00:00AM).

  • If two or more tellers processed the same number of customers, sort them by name in ascending order.

    • A TIMEFRAME is 1 hour long. Example: there are 8 time frames between 08:00AM and 04:00PM: 08AM, 09AM, 10AM, ..., 02PM, and 03PM

    • A time frame covers, for example:

      • 08:00:00AM <= 08AM time frame < 09:00:00AM
      • 03:00:00PM <= 03PM time frame < 04:00:00PM

Hint

In this case there are four tellers and ten customers.

  • Teller 01 processed 4 customers. Three of them were processed in the 08AM time frame, and one was processed in the 10AM time frame.
  • Teller 02 processed 2 customers. Both were processed in the 10AM time frame.
  • Teller 03 processed 3 customers. One was processed in the 02PM time frame, and the other two were processed in the 03PM time frame.
  • Teller 04 had one customer in the queue, but that customer left the queue.

So the teller with the most processed customers is T01 with four, the second busiest teller is T03 with three, and then T02, which processed two.

Customer 01 (CUST01) stands in teller 01's (T01) queue at [T01 CUST01 08:18:55AM], and is processed at [T01 CUST01 08:22:00AM].

Examples1

  1. Example 1

    Input
    T01 CUST01 08:18:55AM
    T01 CUST03 08:20:00AM
    T01 CUST01 08:22:00AM
    T01 CUST02 08:20:23AM
    T01 CUST02 08:25:17AM
    T01 CUST03 08:27:50AM
    T01 CUST04 10:07:46AM
    T01 CUST04 10:19:21AM
    T02 CUST05 10:40:11AM
    T02 CUST06 10:40:18AM
    T02 CUST05 10:44:30AM
    T02 CUST06 10:46:44AM
    T03 CUST07 02:18:55PM
    T03 CUST08 02:19:00PM
    T03 CUST07 03:19:10PM
    T03 CUST08 03:21:27PM
    T03 CUST09 03:26:19PM
    T03 CUST09 03:29:59PM
    T04 CUST10 11:13:34AM
    T04 CUST10
    ENDOFINPUT
    
    Expected output
    T01 4 08AM
    T03 3 03PM
    T02 2 10AM