D: Wood Cutting

https://open.kattis.com/problems/woodcutting

First, there is no reason to cut some of a customer's wood pieces without cutting all of them - this will delay all customers' wait times without any benefit of completing a customer's pieces. So, for each customer we only need to consider the sum of all piece sizes (since we will cut all pieces together)

Next, minimizing average wait time is equivalent to minimizing total wait time, because the number of customers is a constant.

Finally, to minimize total time, sort the customer sums and cut wood pieces from the customer with smallest to largest sum. This is the same reason you do the easiest problems first on a programming contest to minimize total time penalty :)

After summing by customers and sorting, sum up the wait times for the total time, then divide by N to get the average wait time.

Although each customer's wood count is at most 105 10^5 , with 10510^5customers the total time can overflow an int. Make sure to use long long here to avoid overflow!

Last updated