nhphuc's blog

By nhphuc, 13 months ago, In English

Link to problem: https://mirror.codeforces.com/gym/103536/problem/B. (the statement is short so I won't write a summary)

My idea is to use a CHT with the recurrence:

$$$dp_i = a_i * min(b_j,\ b_{j + 1},\ \dots,\ b_i) + dp[j - 1]$$$

(where the $$$a_i$$$ are sorted), but I dont know how to add a line to the CHT structure, is my approach possible, or is there a different way?

Thanks for your help and attention, have a good day !

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
13 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

There's an observation that if you have $$$a_i \lt = a_j$$$ and $$$b_i \lt = b_j$$$, then it is optimal to put $$$i$$$ and $$$j$$$ in one group. Therefore, $$$i$$$-th cat will not influence the result. Therefore, we can remove cats, values of which are "nested" into other cat. As a result, if you sort $$$a$$$ in increasing order, $$$b$$$ will be sorted in decreasing order. Now, you can do CHT.