Under construction

Still being built. Things may change

Card Game (Easy)

Interview

Time limit1sMemory limit1024 MB

Summary
Given sorted attack values and H hit points, find the most cards you can attack with before the opponent dies, or -1 if they never die.
Level

Easy3 of 10

Topics
Greedy, Prefix sum, Sorting
Solved
No attempts yet

Problem

You are playing a card game.

The opponent has HH hit points, and you have NN cards with various attack values. When you attack with a card, the opponent's hit points decrease by that card's attack value. When hit points become 00 or less, the opponent dies.

You want to kill the opponent as late as possible, so you try to kill them using as many cards as possible. Given the attack values in ascending order, find the maximum number of cards you can use. Each card can be used only once.

Input

The first line contains the number of cards NN and the opponent's hit points HH, separated by a space.

The second line contains the attack values did_i of the NN cards in ascending order, separated by spaces.

All input values are integers.

Output

On the first line, print the maximum number of cards you can use to kill the opponent.

If you cannot kill the opponent even after using all the cards, print −1-1.

Constraints

  • 1≤N,H≤1 000 0001 \leq N, H \leq 1\,000\,000
  • 1≤di≤1 000 0001 \leq d_i \leq 1\,000\,000

Examples2

  1. Example 1

    Input
    4 5
    1 2 4 5
    
    Expected output
    3
    
  2. Example 2

    Input
    4 15
    1 2 4 5
    
    Expected output
    -1