Editorial for COCI '15 Contest 6 #3 Pianino
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's denote the keys already pressed as . We define an array of numbers in the following way:
Let's denote the partial sum of array as . It is easy to see that the note that Mirka will press is exactly .
If Mirka plays the note of the song, it holds . If , then the accuracy of the note does not depend on at all, otherwise it will be played correctly if is equal to (notice that the quotient must be a non-negative integer).
Therefore, for each note for which there exists at most one good candidate for . All the candidates can be put in an array and then we can sort them, find the one with the most appearances and choose that one as the optimum.
The complexity of the solution is because of the sorting.
Comments