#P5475. [CCO 2015] 定音鼓手

[CCO 2015] 定音鼓手

Description

This problem is translated from CCO 2015 Day2 T2 "Tiampist".

Computer scientists do not often help percussionists, but today that will change. Since we cannot help all percussionists at once, let us help the timpanist first.

A timpani is a large drum that can be tuned to a specific pitch. A timpanist performs using DD timpani numbered 1D1 \dots D. Now they are playing a measure with NN notes. The ii-th note is played at time TiT_i seconds, and its pitch is PiP_i, where PiP_i is one of the following 12 notes: {F,\{\text{F}, F,\text{F}^♯, G,\text{G,} G,\text{G}^♯, A,\text{A}, A,\text{A}^♯, B,\text{B}, C,\text{C}, C,\text{C}^♯, D,\text{D}, D,\text{D}^♯, E}\text{E}\}.

At any moment, a timpani must be tuned to a pitch before it can be used to play that pitch. Therefore, the timpanist can play note ii if and only if, at time TiT_i, some timpani is tuned to pitch PiP_i.

All notes in this excerpt are within one octave, from F\text{F} up to E\text{E}, which means the possible pitches above are in increasing order. To make computation easier, we will use integers 11 to 1212 to represent these twelve notes.

1 2 3 4 5 6 7 8 9 10 11 12
F\text{F} F\text{F}^♯ G\text{G} G\text{G}^♯ A\text{A} A\text{A}^♯ B\text{B} C\text{C} C\text{C}^♯ D\text{D} D\text{D}^♯ E\text{E}

These are all the pitches that each timpani can be tuned to.

Before the performance starts, the timpanist may freely tune each timpani to any pitch they want. However, during the performance, they may need to quickly retune them in the gaps between notes, so that they can play the correct note at the correct time. The drums are numbered from 11 to DD. At any time, the pitch of drum i+1i+1 must be higher than the pitch of drum ii. The timpanist may retune a drum only when they are not required to play at that moment, and they can retune only one drum at a time (assume no one helps them tune).

Therefore, this is not easy. The timpanist wants to have as much time as possible for retuning. More specifically, they want to maximize the retuning time during the performance so that they can make necessary pitch changes as quickly as possible while playing.

Input Format

The first line contains two integers N,DN, D, representing the number of notes played and the number of drums.

The next NN lines each contain two integers TiT_i and PiP_i, representing the time and pitch of the ii-th note.

Output Format

Output a single line containing one real number, floored to two decimal places, representing the maximum retuning time. Output 0.000.00 if no retuning is necessary.

7 1
100 1
120 3
130 5
140 6
150 8
165 10
170 12
5.00
12 4
0 1
2 1
3 3
6 1
9 6
12 5
21 1
23 1
24 3
27 1
30 8
33 6
4.50
2 4
40287 8
20338194 8
0.00

Hint

[Sample Explanation 1]

If there is only one drum, then to play the next note, the timpanist must retune after every note.

If there are two drums, the answer should be 10.0010.00, achieved when the higher-pitched drum is left tuned to pitch 1212.

[Sample Explanation 2]

Among the first six notes, there are only four pitches: 11, 33, 55, 66. Similarly, among the last six notes, there are only four pitches: 11, 33, 66, 88.

One optimal strategy is to pre-tune four drums to 11, 33, 55, 66. After the sixth note, the timpanist can spend 4.504.50 seconds tuning the highest-pitched drum to pitch 88, then another 4.504.50 seconds tuning the second-highest drum to pitch 66, finishing exactly in time to play the seventh note.

[Sample Explanation 3]

This is a more typical timpani excerpt: it contains only one note, so no retuning is needed.

Constraints

For 60%60\% of the testdata, 1N50,1D31\le N \le 50, 1\le D\le 3.

For 100%100\% of the testdata, 1N100,1\le N \le 100, 1D4,1\le D\le 4, 0T1<T2<...<TN1<TN109,0\le T_1<T_2<...<T_{N-1}<T_N\le 10^9, 1Pi12(1iN)1\le P_i \le 12(1\le i \le N)

Translated by ChatGPT 5