#K53112. Song Collection Management

    ID: 29460 Type: Default 1000ms 256MiB

Song Collection Management

Song Collection Management

You are given a song collection that supports several operations. Each song has a title, an artist, and a duration (in seconds). The collection can perform the following operations:

  • ADD title artist duration: Add a song with the specified title, artist, and duration to the collection.
  • DELETE title: Delete the song with the given title from the collection. If the song exists, print Deleted; otherwise, print Song not found.
  • SORT attribute: Sort the songs by the given attribute which can be one of title, artist, or duration in ascending order, and print the list of song titles separated by commas. (If two songs have the same sorting key, maintain their relative order as in the collection.)
  • TOTAL: Print the total duration of all songs in the collection.

The program will process a sequence of commands from standard input and for each command that requires output (DELETE, SORT, and TOTAL), print the result to standard output.

Note: All songs have single-word titles and artists.

Constraints:

If needed, consider that the number of operations is small enough to run in real-time.

Formally, let \(Q\) be the number of operations. For example, the TOTAL query calculates the sum of durations, i.e. \(\text{total} = \sum_{i=1}^{n} duration_i\).

inputFormat

The first line contains an integer \(Q\) denoting the number of commands.

The following \(Q\) lines each contain a command in one of the following formats:

  • ADD title artist duration
  • DELETE title
  • SORT attribute where attribute is one of title, artist, or duration
  • TOTAL

outputFormat

For each command that requires output:

  • DELETE outputs either Deleted if a song was removed, or Song not found otherwise (each on a new line).
  • SORT outputs a single line of song titles sorted by the specified attribute, separated by commas (with no extra spaces). If the collection is empty, output a blank line.
  • TOTAL outputs a single line with the total duration as an integer.
## sample
5
ADD SongA ArtistA 240
ADD SongB ArtistB 200
TOTAL
DELETE SongB
TOTAL
440

Deleted 240

</p>