#C1790. Treasure Hunt System

    ID: 45034 Type: Default 1000ms 256MiB

Treasure Hunt System

Treasure Hunt System

Implement a treasure hunt system which tracks participants and treasures. The system receives commands from standard input where each command is one of the following:

  • ADD_PARTICIPANT participant_id participant_name
  • ADD_TREASURE treasure_id treasure_value
  • COLLECT_TREASURE participant_id treasure_id
  • TOTAL_VALUE participant_id
  • HIGHEST_COLLECTOR

For the command TOTAL_VALUE, output the sum of treasure values collected by that participant. For HIGHEST_COLLECTOR, output the participant with the highest total treasure value (if tied, choose the one with the smallest participant id). Note that the total value of treasures can be expressed mathematically as \(\sum_{i=1}^{n} value_i\).

inputFormat

The input consists of several lines. Each line contains a command followed by its parameters. Input is read from standard input (stdin).

outputFormat

For each command that requires output (TOTAL_VALUE and HIGHEST_COLLECTOR), print the result on a new line to standard output (stdout). For TOTAL_VALUE output a single integer, and for HIGHEST_COLLECTOR output the participant id and name separated by a single space.## sample

ADD_PARTICIPANT 1 Alice
ADD_TREASURE 101 50
COLLECT_TREASURE 1 101
TOTAL_VALUE 1
HIGHEST_COLLECTOR
50

1 Alice

</p>