#P2676. Minimal Cow Tower
Minimal Cow Tower
Minimal Cow Tower
Farmer John recently added a huge bookshelf to his cow library. However, the shelf was almost instantly filled with books, leaving only the very top accessible. There are \(N\) cows with heights \(H_i\) (\(1 \leq i \leq N\)), and the total sum of all cow heights is \(S\). The bookshelf has a height \(B\) (with \(1 \le B \le S < 2\,000\,000\,007\)).
To reach the top of the shelf (which is higher than the tallest cow), the cows form a tower by standing on each other's backs. The height of the tower is the sum of the heights of the cows in it, and in order to place items on the shelf, the tower’s height must be at least \(B\). Since a tower with more cows is less stable, the cows wish to minimize the number of cows used while still achieving a combined height of at least \(B\).
Your task is to compute the minimum number of cows required to build such a tower.
inputFormat
The first line contains two integers \(N\) and \(B\) separated by a space.
The second line contains \(N\) space-separated integers representing the heights \(H_1, H_2, ..., H_N\) of the cows.
\(1 \le N \le 20\,000\); \(1 \le H_i \le 10\,000\); and \(1 \le B \le S < 2\,000\,000\,007\), where \(S\) is the sum of all \(H_i\).
outputFormat
Output a single integer: the minimum number of cows required such that the sum of their heights is at least \(B\).
sample
3 10
4 3 5
3