Building a Tall Barn
Time limit2sMemory limit512 MB
Assign K cows to N ordered floors, each with work a_i, so each floor gets at least one cow; minimize the sum of a_i/c_i over valid allocations, rounded to nearest integer.
- Level
Hard9 of 10
- Topics
- Greedy, Heap, Math, Binary search
- Solved
- No attempts yet
Problem
Farmer John is building a brand new -story barn with the help of his cows ( and ). To build it as quickly as possible, he needs your help to figure out how to allocate work among the cows.
Each cow must be assigned to work on exactly one of the floors of the barn, and each floor must have at least one cow assigned to it. The -th floor requires units of total work, and each cow completes one unit of work per hour, so if cows work on floor , it is completed in units of time. For safety reasons, floor must be completed before construction can begin on floor .
Compute the minimum total time in which the barn can be completed if the cows are allocated to floors optimally. Output this number rounded to the nearest integer. It is guaranteed that the exact answer is more than 0.1 away from the boundary between two integers.
Input
The first line contains and .
Each of the next lines contains one of , in order. Each value is a positive integer of at most .
Output
Print the minimum time required to build the barn, rounded to the nearest integer.