Official

B - Greedy Division Editorial by evima


Let us assme that, eventually, Takahashi takes Oranges \(x_1,x_2,\cdots,x_k\) and Aoki takes Oranges \(y_1,y_2,\cdots,y_{N-k}\), in these orders.

We can see that, for a fixed pair of sequences \(x\) and \(y\), there is exactly one permutation \(p\) that corresponds to the pair.

Thus, we just have to count the pairs \(x,y\) with the same total weights. We can do it by counting the ways to make \(\sum w_i /2\) with exactly \(k\) oranges, which can be done by DP. The complexity of this solution is \(O(N^2 \max(W_i)^2)\).

posted:
last update: