#CSPS2020D. 贪吃蛇 (Greedy Snake)
贪吃蛇 (Greedy Snake)
Description
There are snake on the grass, numbered from to , respectively. At the begining, stamina of each snake is . We call the snake numbered stronger than the one with number if its current stamina is greater than the other one (), or and .
Then, these snakes will have a duel. The duel will continue for several rounds. In each round, the strongest snake will have two options:
- It will eat the weakest snake and its stamina will decreased by the stamina of that weakest snake. The eaten snake will be removed from the duel.
- It won't eat any snake, the duel will end immediately.
Each snake wants to maximize the number of snake they eat without being eaten (obviously, snakes won't eat themselves).
Suppose every snake is smart enough, calculate the number of snake left after the duel.
This problem has multiple sets of data. For the first set of data, the stamina of each snake will be given in the input. For each subsequent set of data, some snakes' stamina will be changed.
Input Format
The first line contains an integer , the number of dataset.
The following line contains a single integer , the number of snakes.
The third line will contains exactly integers, the -th number represents the -th snake's initial stamina.
The next lines contains dataset, each dataset will have the following format:
- One line contains an integer , the number of snakes whose stamina will be changed.
- One line contains integers and every two integers form a pair which means that the snake number 's stamina will become .
Output Format
Print exactly lines, each represents the number of snakes left after the duel ends with the data provides in the -th dataset.
2
3
11 14 14
3
1 5 2 6 3 25
3
1
2
5
13 31 33 39 42
5
1 7 2 10 3 24 4 48 5 50
5
3
Sample 3
See attached files snakes3.in and snakes3.in
Sample 4
See attached files snakes4.in and snakes4.in
Constraints
For of data, .
For of data, .
For of data, .
For of data, .
For of data, .
It's guaranteed that in every dataset, will be arranged in non-decreasing order.