你可以浏览这个题解的中文版本。
There is the obvious conclusion that choosing ones is equivalent to choosing ones, due to the fact that there is no essential difference between red and blue. This allows us to guarantee .
At this point, there is a greedy conclusion that the red lattice is not continuous. This can be proved by the adjustment method, for example, if the colouring is , the gain at this point is . And if adjusted to , the gain at this point is , which is significantly better.
Thus, the problem is transformed into, pick discontinuous positions, pick the -th position with contribution , and find the maximum contribution. That is, the classical problem of contrite greed P1484 Planting Trees.
Complexity .