Official

A - Schedule Optimization Editorial by evima

Alternative Solution

Similar to the main solution, construct a binary tree and, for each node \(i\), define \(\mathrm{dp}_{i,j}\) as “the minimum cost when the maximum value among \(l_k\) in the subtree rooted at \(i\) is at most \(j\).” This can be represented as a linear function corresponding to intervals up to the number of vertices in the subtree plus one. Considering that the sizes of the subtrees are balanced, we can compute this in \(\mathrm{O}(N^2 2^N)\) or \(\mathrm{O}(N 2^N)\) time.

posted:
last update: