Choose tunings for up to 4 ordered drums before each of N notes so the shortest retuning interval time is maximized; output that time rounded to two decimals.
Hard8Binary searchDynamic programmingGreedyImplementationNo attempts yetTime limit2sMemory limit512 MBA timpano is a large drum that is tuned to one pitch and sounds only that pitch. A player uses D timpani, numbered 1, 2, ..., D from the lowest one up.
The piece to be played has N notes. Note i sounds Ti seconds into the piece and has pitch Pi. Every note of the piece lies inside a single octave, from F up to E, and those twelve pitches are numbered 1 through 12 from the lowest one up.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| F | F# | G | G# | A | A# | B | C | C# | D | D# | E |
A timpano can be tuned only to one of these twelve pitches. A drum sounds only the pitch it is tuned to at that moment, so note i can be played if and only if one of the drums is tuned to Pi at time Ti.
Before the piece starts, the player tunes each drum to any pitch, and that costs no time. During the piece the player has to retune drums to reach the required pitches on time. The rules for retuning are these.
Retuning is hard work, so the player wants as much time as possible for it. Find the time of the shortest retuning in the piece when that time is made as large as possible.
The first line contains the number of notes N and the number of drums D. (1≤N≤100, 1≤D≤4)
Each of the next N lines contains the time Ti and the pitch Pi of note i. (0≤T1<T2<⋯<TN≤109, 1≤Pi≤12)
All input values are integers.
Print on one line the largest time in seconds that the shortest retuning can get. Round the value at the third decimal place and always print two digits after the decimal point. If the whole piece can be played without a single retuning, print 0.00.
The exact answer is a reduced fraction whose denominator is at most D, so the rounding is never ambiguous.