#P2676. [USACO07DEC] Bookshelf B

[USACO07DEC] Bookshelf B

Description

Farmer John recently added a huge bookshelf to the cows' library. Even though it is very large, it was almost instantly filled with all kinds of books. Now, only a little space remains at the very top of the shelf.

All N(1N20,000)N(1 \le N \le 20,000) cows each have a fixed height Hi(1Hi10,000)H_i(1 \le H_i \le 10,000). Let the sum of all cows' heights be SS. The bookshelf has height BB, and it is guaranteed that 1BS<2,000,000,0071 \le B \le S < 2,000,000,007.

To reach the top of the bookshelf, which is higher than the tallest cow, the cows have to perform an acrobatic act by standing on each other's backs, forming a "cow tower." The height of the tower is the sum of the heights of all cows in it. To place items on the top of the bookshelf, the total height of the cows must be at least the height of the bookshelf.

Obviously, the more cows in the tower, the less stable it becomes. Therefore, the cows want to use as few cows as possible while still being able to reach the top of the bookshelf. They ask you to compute this minimum number.

Input Format

  • Line 11: Two integers separated by a space: NN and BB.
  • Lines 2N+12\dots N+1: Line i+1i+1 contains 11 integer: HiH_i.

Output Format

  • Line 11: Output 11 integer — the minimum number of cows needed to stack into a tower to reach the top of the bookshelf.
6 40
6
18
11
13
19
11
3

Hint

Input description:

There are 66 cows, the bookshelf height is 4040, and the cows’ heights are between 6196\dots19.

Output description:

One way to reach height 4040 using only 33 cows: 18+11+1318+11+13. Of course, there are other ways, which are not listed here.

Translated by ChatGPT 5