Bookshelf

Interview

Time limit1sMemory limit128 MB

Summary
Given cow heights and a shelf height B, find the smallest number of cows whose heights sum to at least B.
Level

Easy3 of 10

Topics
Greedy, Sorting, Array, Implementation
Solved
No attempts yet

Problem

Farmer John recently bought a bookshelf for the cow library, but the shelf fills up quickly, and now the only free space left is at the very top.

There are NN cows (1≤N≤200001 \le N \le 20000), and each cow ii has a height HiH_i (1≤Hi≤100001 \le H_i \le 10000). Let SS be the sum of all cow heights. The bookshelf has a height of BB (1≤B≤S<20000000071 \le B \le S < 2000000007).

To reach the top of the bookshelf, which is taller than the tallest cow, one or more cows can stand on top of each other in a stack. The total height of a stack equals the sum of the individual heights of its cows, and this total must be at least the bookshelf height BB. Because stacking more cows than necessary is dangerous, find the smallest number of cows in a stack that still reaches the bookshelf.

Input

  • Line 1: Two space-separated integers, NN and BB
  • Lines 2 to N+1N+1: Line i+1i+1 contains a single integer HiH_i.

Output

  • Line 1: A single integer, the size of the smallest set of cows that can reach the bookshelf.

Hint

For example, when the bookshelf height is 4040, one way to reach it with 33 cows is 18+11+1318+11+13; many other ways exist.

Examples1

  1. Example 1

    Input
    6 40
    6
    18
    11
    13
    19
    11
    
    Expected output
    3