teacher
Sign in

Binary Search on the Answer

When you can quickly test whether a candidate answer works, and bigger candidates never hurt, binary search the answer itself.

40 minCF 1100–17004 interactive12 problems

The problem

A shop must ship n packages in order, one after another, within days days. The ship carries at most cap weight per day, and a package cannot be split. What is the smallest capacity that finishes on time?

For weights 3 2 2 4 1 4 and 3 days the answer is 6.

1 of 10