Hide

Problem D
Kangaroo Hop

/problems/kangaroohop/file/statement/en/img-0001.jpg
A family of kangaroos come upon one end of a row of delicious-looking flowers. The father jumps to the biggest flower. The mother jumps to the next biggest flower that could be closer or farther away from the father’s. (Kangaroos are quite capable of jumping over other kangaroos.) The young ones (called joeys) follow up one by one, jumping along the row to the next biggest flowers. By this time the father has finished eating his flower and jumps again, further down the row. They continue in this fashion, taking turns. A kangaroo exits the row when there are no more flowers in front, and the others continue taking turns until they too run out of flowers that are in front of them. They never look back, so when the last kangaroo exits the row, it’s possible some flowers are missed. Your task is to determine how many flowers are missed. You will be provided with the sizes of the flowers in the row, in order, and the number of kangaroos in the family.
/problems/kangaroohop/file/statement/en/img-0002.jpg
Illustration of Sample 1

Input

The first line will be an integer $k$, $0 <= k <= 14$, representing the number of kangaroos in the family. On the next line will be an integer $n$, $0 <= n <= 200$, representing the number of flowers. The next $n$ lines will each have a single integer on them representing the size of a flower. All flowers will have size of at least 1 and none will be greater than 1000. The flowers are presented in the order they appear in the row, so the first is the closest to the approaching family.

In Sample 1, there are 4 in the family and 9 flowers. Father jumps to the 9 flower. Mother jumps to the 8 flower. Joey 1 jumps to the 7 flower. Joey 2 jumps to the 6 flower. Father then jumps to the 4 flower. Mother jumps to the 3 flower. Joey 1 jumps to the 1 flower. Joey 2 exits, seeing no more flowers. Father exits. Mother exits. Two flowers, sizes 5 and 2, remain uneaten.

Output

Print a single integer indicating the number of flowers that are not eaten by this family of kangaroos.

Sample Input 1 Sample Output 1
4
9
5
8
2
7
1
6
3
9
4
2
Sample Input 2 Sample Output 2
4
9
10
20
30
40
50
60
70
80
90
5

Please log in to submit a solution to this problem

Log in