This problem is loosely based on real events.
The organising committee of an unspecified programming contest (UPC) is planning to hold many rounds this year, each round consisting of problems of varying difficulties.
As such, there have been very many problem proposals. Each problem proposal has been assigned a difficulty rating between and .
The difficulty rating for a specific problem can either be:
- An integer () — meaning that this problem is appropriate only as the -th problem in an UPC round; or
- Equal to , for some integer () — meaning that this problem is appropriate as either the -th or the -th problem problem in an UPC round.
Task
Given (the number of problems in an UPC round), and the number of problem proposals for each difficulty rating, print the maximum number of rounds that can be held using these problems.
Note that each problem can only be used in at most one round.
Input data
Each test contains multiple test cases. The first line of input contains a single integer — the number of test cases.
The first line of each test case contains a single integer — the number of problems in an UPC round.
The second line of each test case contains integers , where denotes the number of problem proposals with a difficulty rating of .
The third line of each test case contains integers , where denotes the number of problem proposals with a difficulty rating of .
Output data
For each test case, print a single integer, the maximum number of rounds that can be held using the available problems.
Constraints and clarifications
- for each
- for each
- It is guaranteed that the sum of across all test cases does not exceed .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 5 | |
3 | 10 | and |
4 | 30 | and |
5 | 20 | |
6 | 35 | No additional constraints |
Example
stdin
5
6
0 1 1 0 1 1
1 0 1 0 1
5
0 1 1 1 0
1 0 1 0
2
1 1
2
6
0 0 0 0 0 0
5 2 5 100 9
7
1 3 0 4 1 0 2
4 3 1 3 1 5
stdout
1
0
2
3
4
Explanation
In the first test case, there are problem proposals, which have difficulty ratings of , , , , , and , respectively.
We can create a single round using these problems:
- The problem with a difficulty rating of will be used as the first problem in the round.
- The problem with a difficulty rating of will be used as the second problem in the round.
- The problem with a difficulty rating of will be used as the third problem in the round.
- The problem with a difficulty rating of will be used as the fourth problem in the round.
- The problem with a difficulty rating of will be used as the fifth problem in the round.
- The problem with a difficulty rating of will be used as the sixth problem in the round.
In the second test case, we can show that it is impossible to create a complete round from the given proposals.
In the third test case, it is possible to create the following rounds from the given proposals:
In the fourth test case, it is possible to create the following rounds from the given proposals: