Dynamic Programming21 sections · 916 units
Open in Course

Building a Tall Barn - Problem Statement

USACO Platinum

You're building an NN-story barn with KK cows. Each cow is assigned to exactly one floor, each floor has at least one cow. Floor ii requires aia_i work, and with cc cows it takes ai/ca_i / c time. Find the lowest total time. Example: 33 floors with work [1010, 2020, 3030], 55 cows.

If you assign 11, 22, 22 cows to floors 11, 22, 33, total time = 10/1+20/2+30/2=10+10+15=3510/1 + 20/2 + 30/2 = 10 + 10 + 15 = 35. This problem beautifully illustrates why convexity holds. Adding more cows gives diminishing returns. Think about it: the first cow on a floor cuts time by half, the second cuts it by a third, etc.