Editorial for DMOPC '14 Contest 2 P3 - Sawmill


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

A greedy solution works here. Pair them up so that the cheapest saw (lowest energy consumption rate) is matched with the longest log. You can prove this is optimal by a simple exchange argument. Be careful Java users, don't use Arrays.sort on primitives. Also, the answer will not fit in an int, so use a long (cast to long when multiplying too).


Comments

There are no comments at the moment.