Under construction

Still being built. Things may change

Rhythm Game

Interview

Time limit1sMemory limit1024 MB

Summary
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 44\frac{4}{4} 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 bb, then bb 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 NN, the initial BPM S0S_0, and the number of tempo changes KK, separated by spaces. (0≤K<N≤1050\leq K<N\leq 10^{5}, 1≤S0<10001\leq S_0<1000)

Each of the next KK lines contains the measure MiM_i where the ii-th tempo change happens, and the new BPM SiS_i after that change. (1<Mi≤N1<M_i\leq N, 1≤Si<10001\leq S_i<1000)

N,K,M1,M2,⋯ ,MKN, K, M_1, M_2, \cdots, M_K are all integers. SiS_i 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, 1<M1<M2<⋯<MK1 < M_1 < M_2 < \cdots < M_K.

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 10−610^{-6}.

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}')

Examples1

  1. Example 1

    Input
    10 120.0 2
    4 180.0
    7 60.0
    
    Expected output
    26.000000000000