Editorial for DMPG '19 G2 - Test Marks


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.

Author: r3mark

Observe that the final marks should be a non-decreasing sequence. (The observation was not true for the original problem, which was incorrect as a result.) This is because it never hurts Bob to swap marks mi and mj if mi>mj and i<j, since the v array is non-decreasing.

With this observation, a dynamic programming solution can be found for the first subtask. Let dp[i][j][e] be the most amount of money given that only the first i tests are being considered, mi=j, and e=m1+m2++mi. Then the transition can be done in O(N) by considering the length of marks equal to exactly j. The rest of the marks will definitely be less than mi and will contribute to the money earned.

Time Complexity: O(N3E)

For the second subtask, a similar approach is used. Instead of considering the tests from 1 to N, this dynamic programming solution considers the tests from N to 1. The advantage here is the dimension [j] in the first subtask is no longer necessary, as mi should always be equal to 0. So let dp[i][e] be the most amount of money given that only the last Ni+1 tests are being considered and e=mi+mi+1++mN. If mi=mj<mj+1, that is equivalent to adding 1 to all the marks in the transition. So

dp[i][e]=minj>idp[j+1][e(Nj)]+(ji+1)(vj+vj+1++vN)

Then the transition can be done in O(N).

Time Complexity: O(N2E)

For the final subtask, note that the convex hull optimization can be applied to the dynamic programming solution from the second subtask. This changes the transition into amortized O(1).

Time Complexity: O(NE)


Comments

There are no comments at the moment.