UVALive 6771 - Buffed Buffet （斜率优化）

This one was deceptively sneaky, but the principles are reasonably simple. It’s not too hard to guess that one will solve the continuous and discrete problems separately, and then consider all partitions between the two.

Let’s start with the continuous problem, since it is a little easier. I don’t have a formal proof, but it shouldn’t be too hard to convince yourself that a greedy strategy works. We start by eating the tastiest food. Once it degrades to being as tasty as the second-tastiest food, we then each both, in the proportion that makes them decay at the same rate. In fact, at this point we can treat them as a combined food with a combined (slower) decay rate. We continue eating this mix until tastiness decays to match the third-tastiest, and so on. There are some corner cases that need to be handled if there are foods that don’t decay.