Editorial for COCI '12 Contest 1 #2 F7
Submitting an official solution before solving the problem yourself is a bannable offence.
Let us sort the drivers in descending points order and select the driver in that sorted order. We need to determine whether (s)he can be the World Champion.
We can construct the best possible final race scenario for that driver. In such a race, (s)he would earn points, while the current champion would earn only
point, the current runner-up only
points and so on. Generally, the driver in position
earns
points; drivers in positions
are irrelevant since they cannot have more points than driver
in the constructed scenario.
Can driver be the World Champion in this scenario? The answer is 'yes' if (s)he has a sum greater than all other drivers, that is, if the relation
is satisfied, where is the number of points that driver
in the descending sequence had before the final race.
The solution that computes the maximum above (let us denote it by ) for every
from scratch has complexity
, which is too slow. Fortunately, the maximum is simple to compute gradually as needed: whenever the observed
is incremented, we can compare the previous maximum value with the current point value and update the maximum if needed. To formalize,
This reduces the complexity of finding the solution to . The total complexity is
because of sorting.
Comments