Rhythm Game
InterviewTime limit1sMemory limit1024 MB
Given N measures with BPM changes at certain measures, compute the song's total play time in seconds, where each measure has 4 beats.
- Level
Easy2 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Rhythm Game Lead Ray is building a rhythm game. The game has many songs, and Ray wants the song selection screen to show each song's total play time in advance. To understand how a song is built, you need to know the following terms.
- Measure is the smallest unit of length in a song. A song is made of several measures.
- Beat is a unit of rhythm within a measure. Every song in this rhythm game is in time, so each measure has 4 beats.
- BPM (Beats Per Minute) is the unit of song speed. It is the number of beats played in one minute. If a song has BPM , then beats pass at a constant rate every minute.
- The BPM can change in the middle of a song. This is called a tempo change. A tempo change can happen at the start of each measure. The new BPM stays in effect until the next tempo change or until the song ends.
Given the total number of measures, the initial BPM, and the tempo change information, find the total play time of the song.
Input
The first line contains the number of measures , the initial BPM , and the number of tempo changes , separated by spaces. (, )
Each of the next lines contains the measure where the -th tempo change happens, and the new BPM after that change. (, )
are all integers. is a positive real number with at most 2 digits after the decimal point.
The tempo changes are given in measure order. At most one tempo change happens in a single measure. No tempo change happens in the first measure. In other words, .
Output
Print the total play time of the song in seconds on the first line.
Your answer is accepted if its absolute or relative error is at most .
For exact checking, printing the answer in fixed-point format with at least 12 digits after the decimal point is recommended. See the hint for how to print it.
Hint
To print the answer ans with 12 digits after the decimal point, use the following for each language. For other languages, check the language reference.
- C:
printf("%.12f\n", ans); - C++:
std::cout << std::fixed << std::setprecision(12) << ans << std::endl; - C#:
Console.WriteLine(String.Format("{0:F12}", ans)); - Java:
System.out.printf("%.12f\n", ans); - Python:
print(f'{ans:.12f}')