#C5581. Song Database Management

    ID: 49246 Type: Default 1000ms 256MiB

Song Database Management

Song Database Management

In this problem, you are asked to build a simple song database management system. The system supports the following operations:

  1. add: Add a song to the database with a unique song identifier, a title, and a duration (in seconds).
  2. delete: Remove a song from the database using its song identifier.
  3. total: Compute and output the total duration of all songs in the database. Mathematically, if there are n songs with durations (d_1, d_2, \ldots, d_n), then the total duration is given by (\sum_{i=1}^{n} d_i).
  4. longest: Find and output the song with the maximum duration. The output should be in the format: song_id title duration. If there is no song in the database, output None.

You will receive a series of commands as input. Process each command and output the result for commands total and longest.

Note: All input is given via standard input and all output should be written to standard output.

inputFormat

The input begins with a single integer T specifying the total number of commands. This is followed by T lines, each containing one command. The commands can be of the following forms:

  1. add id title duration (\rightarrow) Add a new song with the given id (an integer), title (a string without spaces), and duration (an integer).

  2. delete id (\rightarrow) Delete the song with the given id if it exists.

  3. total (\rightarrow) Output the total duration of all songs currently in the database.

  4. longest (\rightarrow) Output the song id, title, and duration of the song with the maximum duration. If no songs exist, output None.

outputFormat

For each command of type total or longest, output the corresponding result on a new line.

For total, output a single integer representing the sum of durations of all songs. For longest, output three space-separated values: the song id, the song title, and the song duration. If there is no song in the database, output None.## sample

8
add 1 SongOne 210
add 2 SongTwo 320
add 3 SongThree 300
total
longest
delete 2
total
longest
830

2 SongTwo 320 510 3 SongThree 300

</p>