Wildest Dreams
Time limit1sMemory limit1024 MB
For each CD and day, compute the seconds Arup spends playing Anya's favorite track, given the track lengths and her driving segments.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Arup secretly loves Taylor Swift's music. To cover for it, he tells people that his three-year-old daughter Anya makes him play the CD in the car whenever she is in it. In fact, he also listens to the CD when Anya is not in the car.
Anya usually obsesses over one song and asks Arup to play it on infinite repeat while she is in the car. When she gets in, Arup starts that song from the beginning, and it repeats until she gets out. After she gets out, Arup plays the CD in its natural order, and after the last track it returns to track 1. If the favorite track is playing when Anya gets out, that track plays to its end before the CD moves on. If the song ends exactly when she gets out, the next track plays, and the favorite song does not start over.
Given the track lengths for each CD, compute for each day the total time Arup listens to Anya's favorite track.
Input
The first line contains (), the number of CDs.
For each CD, the first line contains (), the number of tracks, and (), the track Anya is obsessed with. The second line contains positive integers, the length of each track in seconds, in order. No CD is longer than 86400 seconds.
The next line contains (), the number of days. Each of the next lines starts with (), the number of driving segments, followed by positive integers, the lengths of the segments in seconds. Anya is in the car during the odd-numbered segments (first, third, and so on). The segments of each day sum to at most 86400.
Output
For each CD, print a line "CD #c:", where c is the CD number starting at 1. Then print one line for each of its days with the number of seconds Arup spent listening to Anya's favorite song that day. Print a blank line after each CD's output.