Dima and the Construction Set
InterviewTime limit2sMemory limit1024 MB
Given n stack heights a_i and k extra pieces, find the largest h such that every stack can be raised to at least h.
- Level
Easy3 of 10
- Topics
- Binary search, Greedy
- Solved
- No attempts yet
Problem
Leha <> gave Dima a construction set. Dima is well past childhood, yet he was delighted, since such toys had never been sold in Bataysk.
Input
The fence is a row of pieces, and on each piece some more pieces are stacked. Call such a stack a segment. The height of a segment is the number of pieces in it. To upgrade the fence, Dima places pieces on top of some segments. He does not touch pieces that are already there. Dima has extra pieces. Find the maximum height the fence can reach after the upgrade. The height of the fence equals the height of its shortest segment.
Output
The first line contains two integers and (; ), the width of the wall in pieces and the number of extra pieces. The second line contains integers (), the height of each segment.
Dima and the Construction Set
Print one integer , the maximum height of the fence Dima can get after the upgrade.