Portal Kombat
InterviewTime limit5sMemory limit128 MB
Hektor absorbs the strength of each weaker opponent he beats, and the goal is the fewest wins that let him defeat the strongest opponent.
Problem
Hektor's favorite computer game is Portal Kombat, a game in which the player takes on the role of a warrior dueling computer-controlled opponents. Every character in the game (both Hektor and his opponents) has a fixed strength value.
The strength of the computer-controlled opponents never changes and is known to Hektor at all times. Hektor's own strength, however, grows with every victory. In each round Hektor picks one opponent to duel.
- If Hektor is strictly stronger, he wins the duel. The defeated opponent is removed from the game, and Hektor's strength increases by the defeated opponent's strength.
- If Hektor and his opponent have equal strength, the duel is a draw and nothing happens.
- If Hektor is weaker, he loses the game.
Given Hektor's strength and the strength of each opponent, compute the minimum number of rounds needed until Hektor defeats the strongest opponent.
Input
The first line of input contains the number of test sets (). The test sets follow, one after another.
The first line of each test set contains two natural numbers and (). is Hektor's initial strength and is the number of opponents.
The second line of each test set contains natural numbers () describing the opponents' strengths. The values are given in non-decreasing order.
Output
For each test set, print on its own line the minimum number of rounds needed to defeat the strongest opponent, or the word NIE if Hektor can never do it.