(Anti) Social Snake

0

0 votes
Medium
Problem

Vader decides to create a modified version of the popular game - 'Snake'. In Vader's version of the game, there are multiple snakes scattered all over the game arena. A snake can 'gobble up' another snake only when it has a size greater than the size of the other. When a snake gobbles up another snake, its size increases by the size of the other snake. A user playing the game wins when he gobbles up all the other snakes in the game arena.

In Vader's game, a player plays against snakes generated and controlled programatically (i.e. against the Computer). Vader, being the nice person that he is, wants the game to be winnable - i.e. if a user is fast and smart enough to avoid getting eaten by snakes bigger than itself - then it should be possible for the user's snake to gobble up all the others in at least one sequence of valid moves. Vader's intern writes a program that generates snakes of arbitrary sizes for him. However, it is possible that for the snakes that the program generates, there is no sequence of valid moves (gobbles) for which a player can win the game. He comes to you for help, and asks you to fix this. You are allowed two operations - you can add a snake of any positive integral size to the game arena, or you can remove any one of the existing snakes. What is the minimum number of times you can perform these operations to ensure that the game becomes winnable?

Input Format

The first line contains a single integer T representing the number of sub-tests . T sub-tests follow.

The first line of each sub-test contains two space-separated integers - X, representing the size of the player's snake, and N, representing the number of other snakes in the game arena. The next line contains N space separated integers - representing the sizes of the other snakes on the board.

Output Format

For each sub-test, output a single line containing the minimum number of operations needed to make the game winnable.

Constraints

1 <= T <= 100

1 <= X <= 1000000

1 <= N <= 100

Note

There is no partial scoring for this problem.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?