#C9085. Create a Movie Playlist
Create a Movie Playlist
Create a Movie Playlist
You are given a list of movies, each described by a genre, a title, and a duration. Your task is to create a playlist consisting only of movies belonging to a specified genre such that the total duration does not exceed a given limit.
You must filter the movies by the given genre, sort the filtered movies in ascending order by their duration, and then select movies one by one until adding the next movie would exceed the maximum duration.
If no movie can be selected, output No movies available. Otherwise, print the titles of the selected movies separated by a single space.
Note: Any mathematical expressions or formulas (if needed) should be formatted in \( \LaTeX \) format.
inputFormat
The input is read from STDIN and has the following format:
- The first line contains an integer \(n\) representing the number of movies.
- The next \(n\) lines each contain a movie's information: genre (string), title (string), and duration (integer), separated by spaces.
- The final line contains the target genre (string) and the maximum total duration (integer), separated by a space.
outputFormat
Print a single line to STDOUT:
- If one or more movies can be selected, output their titles in the order they are chosen (separated by a single space).
- If no movies can be selected, output No movies available.
5
Action DieHard 120
Action MadMax 150
Drama Titanic 180
Drama TheGodfather 175
Action Speed 100
Action 250
Speed DieHard
</p>