Editorial for DMOPC '19 Contest 6 P6 - Math is Difficult
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
A brute force solution suffices for this subtask.
Time Complexity:
Let's say student
Previously,
Time Complexity:
Firstly, calculate the penalty for each student assuming that they don't ask for help. The penalty for a student who has solved
This can be calculated quickly using a prefix sum array (there are other ways to do this as well).
Now, we just have to find the maximum penalty loss a student can obtain.
Consider problem #
Let
Let
A student who solves problem
Additionally, if we loop through the students from most problems solved to least problems solved, problems become available for extra help in the order of highest index to lowest index (and don't ever become unavailable). Thus, we can simply insert problems into a data structure when they become available, and query for the maximal value at a certain
The only issue left is that for each student, we query
A data structure that maintains this set of available lines efficiently is the Dynamic Convex Hull Trick.
Time Complexity:
We can expand on our solution from subtask 3 to account for the availability of help on certain days.
We can do this with a segment tree:
When querying for student
This can also be done using divide and conquer: solve(l, r)
considers only the problems and students available in the days solve(l, mid)
and solve(mid + 1, r)
respectively, where solve(1, D)
will compute the answer for each student and we can simply print it out afterwards.
Time Complexity:
There is also a solution with complexity
As always, feedback is welcome.
Comments