DMOPC '22 Contest 2 P5 - Beautiful Bins

View as PDF

Points: 30
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

bins are lined up in a row, numbered to from left to right. Bin initially contains balls, and it is considered beautiful if it contains balls. In one move, you may pick a bin with at least balls, move one ball from bin to any bin on its left, and move another ball from bin to any bin on its right. After some sequence of moves, is it possible to make all of the bins beautiful? To ensure the integrity of your solution, there may be up to test cases.

Constraints

The sum of over all test cases does not exceed .

Input Specification

The first line contains a single integer , the number of test cases. The next lines describe the test cases.

The first line of each test case contains a single integer .

The second line of each test case contains integers .

The third line of each test case contains integers .

Output Specification

For each test case, output a single line containing YES if it is possible to make all of the bins beautiful or NO otherwise.

Sample Input

2
5
2 4 4 2 1
4 3 1 3 2
5
1 1 2 4 2
4 3 4 1 3

Sample Output

YES
NO

Explanation for Sample

For the first test case, one possible solution is as follows:

1. Move one ball from bin to bin and another from bin to bin . The number of balls in each bin is now .
2. Move one ball from bin to bin and another from bin to bin . The number of balls in each bin is now .
3. Move one ball from bin to bin and another from bin to bin . The number of balls in each bin is now .

For the second test case, it can be proven that it is impossible to make all of the bins beautiful.