#K111. Top Customer Identification

    ID: 23393 Type: Default 1000ms 256MiB

Top Customer Identification

Top Customer Identification

Given a list of call records and a date range, identify the customer with the highest total call duration within the specified dates. Each call record consists of a user ID, a date in YYYY-MM-DD format, and a call duration represented as an integer (in minutes). If a call's date falls within the inclusive range from start_date to end_date, its duration contributes to the customer's total. In case of a tie (i.e. two or more customers having the same total call duration), the customer whose last valid record appears later in the input is chosen. If no call record falls within the given date range, output None.

The problem can be mathematically represented as follows. Let \( D(u) = \sum_{i \in I(u)} d_i \), where \( I(u) \) is the set of indices for call records of customer \( u \) that satisfy \[ start\_date \leq date_i \leq end\_date, \] and \( d_i \) is the duration of the \( i^\text{th} \) call. The task is to find the customer \( u^* \) such that \[ u^* = \operatorname*{argmax}_{u} \Bigl( D(u),\, pos(u) \Bigr), \] where \( pos(u) \) represents the last occurrence (index) of a valid call record for customer \( u \).

inputFormat

The input is given via standard input (stdin).

  • The first line contains two space-separated strings: start_date and end_date in the format YYYY-MM-DD.
  • The second line contains an integer n, the number of call records.
  • Each of the following n lines contains a call record with three space-separated fields: user_id (a string), date (in YYYY-MM-DD format), and duration (a positive integer as a string).

outputFormat

Output a single line to stdout containing the user ID of the top customer. If there are no call records within the given date range, output None.

## sample
2023-01-01 2023-01-03
5
user1 2023-01-01 30
user2 2023-01-02 45
user1 2023-01-04 60
user3 2023-01-03 50
user2 2023-01-03 40
user2