Card Game (Easy)
InterviewTime limit1sMemory limit1024 MB
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 hit points, and you have 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 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 and the opponent's hit points , separated by a space.
The second line contains the attack values of the 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 .