Osmos (Small)
InterviewTime limit5sMemory limit512 MB
Starting from size A, sort the other motes and absorb each smaller one, adding helper motes or deleting blockers for the fewest operations.
Problem
Armin is playing Osmos, a physics puzzle game made by Hemisphere Games. He controls a mote, a small particle that moves around and absorbs motes smaller than itself.
When Armin's mote absorbs a smaller mote, it grows by the size of the mote it absorbed. Once it is bigger, it absorbs motes that were out of reach before. Suppose Armin's mote has size 10 and the other motes have sizes 9, 13 and 19. At the start only the mote of size 9 can be absorbed, and absorbing it brings Armin's mote to size 19. Next it absorbs the mote of size 13 and reaches size 32, and only then does it absorb the last mote.
A mote is absorbed only when it is strictly smaller than Armin's mote. A mote of the same size cannot be absorbed.
You are in charge of the program that lays out the motes. The layout it produced may leave Armin's mote unable to absorb everything. You may perform two kinds of operations, in any order and any number of times: add one mote whose size is a positive integer, or remove one mote that is already in the game. One add and one remove each count as one operation. Find the minimum number of operations that lets Armin's mote absorb every other mote.
For example, if Armin's mote has size 10 and the other motes have sizes 9, 20, 25 and 100, the layout cannot be cleared as it stands. Adding a mote of size 3 and removing the mote of size 100 clears it in two operations, and one operation is not enough.
Input
The first line contains the number of test cases . Each test case takes two lines. The first line has the size of Armin's mote and the number of other motes . The second line has the sizes of the other motes. Every size is an integer.
Limits
- every mote size is between 1 and 100
Output
For each test case, print one line of the form Case #x: y, where x is the test case number starting from 1 and y is the minimum number of operations that makes the game solvable.
Hint
Mote sizes in the input never go above 100, but Armin's mote grows past that limit while it absorbs.
A mote you add stays in the game, so it has to be absorbed as well.
Osmos was made by Hemisphere Games. This problem has no connection to Hemisphere Games.