Download Bubble Shooter

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Bubble Shooter
Mani is playing a very addictive bubble shooting game.
The rules of this game are very simple.
When you shoot at a ball, that ball will fall along with all the other balls, which are present below this
ball and are connected to this ball.
Mani is very bored right now and hence shoots any ball that is attractive to him.
The game consists of a total of N balls numbered from 1 to N
You are given a sequence of numbers S, the numbers of the balls shot by Mani, in no particular order.
Given this sequence, find the minimum number of balls that Mani could have shot to achieve the same
result
The connection of balls forms a tree structure, given by the diagram below.
1
/ \
2
3
/\ /\
4 56 7
............... To infinity
Each of the numbers in the tree represent a ball number.
Mani is very talented. He is capable of shooting any ball at any stage of the game ;)
Input Format
Input consists of 2 lines.
The first line contains N, the number of balls present initially and K,the number of balls shot by Mani.
The second line contains K distinct space separated integers, which are the elements of sequence S
CONSTRAINTS:
1 <= N <= 109
1 <= K <= 104
K <= N
Output Format
Output consists of 1 line , containing the answer to the problem
Sample Input
Sample Test 1:
73
123
Sample Test 2:
72
23
Sample Output
Sample Test 1:
1
Sample Test 2:
2
Explanation
The game in both test cases corresponds to the diagram shown in Figure with N = 7.
For the first test case,
Destroying 2 will destroy the balls 2,4,5.
Destroying 3 will destroy the balls 3,6,7.
Destroying 1 will destroy the balls 1,2,3,4,5,6,7
Since destroying ball 1 alone will be enough to destroy all balls destroyed by all the 3 balls together,
answer is 1 in this case.
For the second test case, it can be seen that Mani has followed the best strategy. So, the answer is 2.