Editorial for Expensive Chair Stacking
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
I wanted to add a series of quick solution sketches to my problems without one. These aren't technically full editorials, but I hope that they are enough for you if you are stuck. :-)
The first two subtasks were meant to reward various brute force approaches.
The third subtask was solvable by considering the and axes separately. Consider the axis: if we let be the total payment of moving all chairs to position , we note that is convex. Thus, we can binary search for the best position (and repeat for the axis).
The final subtask extends on the third subtask a bit, noting that the position where is maximized is either or , allowing us to solve the problem in linear time. As is very large, be careful with implementation.
Comments