This page is still under construction.

Parts of this page are still being built. What you see may change.

Portal Kombat

Interview

Time limit5sMemory limit128 MB

Summary
Hektor absorbs the strength of each weaker opponent he beats, and the goal is the fewest wins that let him defeat the strongest opponent.
Level

Medium5 of 10

Topics
Greedy, Sorting, Heap
Solved
No attempts yet

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 ZZ (1≤Z≤101 \le Z \le 10). The test sets follow, one after another.

The first line of each test set contains two natural numbers PP and NN (1≤P,N≤1061 \le P, N \le 10^6). PP is Hektor's initial strength and NN is the number of opponents.

The second line of each test set contains NN natural numbers XiX_i (1≤Xi≤1061 \le X_i \le 10^6) describing the opponents' strengths. The values XiX_i 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.

Examples1

  1. Example 1

    Input
    3
    3 5
    2 4 6 6 8
    3 5
    1 1 2 2 2
    3 5
    1 1 5 6 7
    
    Expected output
    3
    1
    NIE