Problemsetting

Time limit: 1.5s Memory limit: 256MB Input: Output:

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 nn problems of varying difficulties.

As such, there have been very many problem proposals. Each problem proposal has been assigned a difficulty rating between 11 and nn.

The difficulty rating for a specific problem can either be:

  • An integer ii (1in1 \leq i \leq n) — meaning that this problem is appropriate only as the ii-th problem in an UPC round; or
  • Equal to i.5i.5, for some integer ii (1i<n1 \leq i < n) — meaning that this problem is appropriate as either the ii-th or the i+1i+1-th problem problem in an UPC round.

Task

Given nn (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 tt — the number of test cases.

The first line of each test case contains a single integer nn — the number of problems in an UPC round.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots , a_n, where aia_i denotes the number of problem proposals with a difficulty rating of ii.

The third line of each test case contains n1n − 1 integers b1,b2,,bn1b_1, b_2 , \dots , b_{n−1}, where bib_i denotes the number of problem proposals with a difficulty rating of i.5i.5.

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

  • 1t10 0001 \leq t \leq 10 \ 000
  • 2n200 0002 \leq n \leq 200 \ 000
  • 0ai1 000 000 0000 \leq a_i \leq 1 \ 000 \ 000 \ 000 for each 1in1 \leq i \leq n
  • 0bi1 000 000 0000 \leq b_i \leq 1 \ 000 \ 000 \ 000 for each 1i<n1 \leq i < n
  • It is guaranteed that the sum of nn across all test cases does not exceed 200 000200 \ 000.
# Points Constraints
1 0 Examples
2 5 bi=0b_i = 0
3 10 ai1a_i \leq 1 and bi1b_i \leq 1
4 30 ai100a_i \leq 100 and bi100b_i \leq 100
5 20 ai=0a_i = 0
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 77 problem proposals, which have difficulty ratings of 1.51.5, 22, 33, 3.53.5, 55, 5.55.5 and 66, respectively.

We can create a single round using these problems:

  • The problem with a difficulty rating of 1.51.5 will be used as the first problem in the round.
  • The problem with a difficulty rating of 22 will be used as the second problem in the round.
  • The problem with a difficulty rating of 33 will be used as the third problem in the round.
  • The problem with a difficulty rating of 3.53.5 will be used as the fourth problem in the round.
  • The problem with a difficulty rating of 5.55.5 will be used as the fifth problem in the round.
  • The problem with a difficulty rating of 66 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:

  • [1,1.5][1,1.5]
  • [1.5,2][1.5,2]

In the fourth test case, it is possible to create the following rounds from the given proposals:

  • [1.5,1.5,3.5,3.5,5.5,5.5][1.5,1.5,3.5,3.5,5.5,5.5]
  • [1.5,1.5,3.5,3.5,5.5,5.5][1.5,1.5,3.5,3.5,5.5,5.5]
  • [1.5,2.5,2.5,3.5,5.5,5.5][1.5,2.5,2.5,3.5,5.5,5.5]

Log in or sign up to be able to send submissions!