F - CatCoder Triple Contest Editorial by qiuzx_

How to solve F using A

We can see from problem A that the answer is \(\min(\sum\min(a_i,b_i),\sum\min(b_i,c_i),\frac{\sum\min(b_i,a_i+c_i)}2)\) with two contests.

Suppose we fix the number of the first kind of contests for each person, let it be \(i\). Then for that person, we can set \(a'=b-i,b'=\min(c-i,d),c'=e\), which stands for the case with \(3\) types of problems and \(2\) contests.

This will be the same problem as A, so we let \(f_i,g_i,h_i\) denote the maximum value of the three sums in the solution to A respectively, when the total number of type \(1\) contests is \(i\).

For every new person, we do a \((\max,+)\) convolution to each of \(f,g,h\) with a function like \(\min(a-x,b)\). It’s easy to see that after updating, \(f,g,h\) will still be in a shape like \(\min(a'-x,b')\), so we keep track of \(a',b'\) to update in \(O(1)\) time.

For a query, we can do a binary search on \(i\) since \(f,g,h\) are all monotonic. Or we can do some casework and answer it in \(O(1)\), which is optional.

posted:
last update: