Editorial for CEOI '16 P5 - Popeala
Submitting an official solution before solving the problem yourself is a bannable offence.
Editor's note: This editorial has been copied from Codeforces. The official editorial seems to be unrelated.
the minimum cost we can obtain if we take the first
test cases and put them in
groups.
, where
is the last test of the previous group and
is the total score the participants will obtain on tests
-
if we group them.
The complexity is but it is too big for 100 points. Let's assume that we are at test
. Let's keep for each of the
participants the most recent test he failed and denote it with
. For contestant
,
,
and
failed test
.
Using those values, we will divide our tests into
groups. Group
consists of all test cases from the most recent
until
(basically, no one fails any tests in this group). Group
consists of all test cases from the second most recent
until the most recent
(only one participant fails the groups), etc. Let's denote for each group
:
, where
is the best option we can select for our dynamic programming with the restriction that
is a test from group
. Formally:
is minimal for all
from group
. If we know for each group this best, we will have to check only
different possibilities (since there are only
groups) and take the best option.
Let's assume that we solved , formed all the groups and computed each
. Let's see what happens when we go to test
. Assume initially that all participants pass this test. One of the key observations is that the "
" values do not change (all options increase with the same value in the same group), so we just have to recheck all the
possibilities. Now let's assume that contestant
fails test
. The main modification is that
becomes
, so the groups change their configuration:
- The previous
was dividing 2 groups which now have merged into one. To compute the new best of this new group it is enough to just compare the two old options and take the best one.
- All the options from the previous
to the new one change their value in the recursion. Unfortunately, it is necessary to loop throw all of them again since they changed drastically. Fortunately, we can do that with brute force and the complexity will not change (because a passed test will be recomputed only once between 2 consecutive failed tests).
The final complexity is .
Comments
Wrong editorial for the problem.
Here is the right one: https://codeforces.com/blog/entry/46065?#comment-332744
Updated the editorial