本题来源于:DMOPC '22 Contest 2 第五题
由于洒水消耗的体力过大,筋疲力尽的小亮现在连最基本的数论题都解决不了了,于是他开始对着一排筐子里的球玩了起来。
有一排 个筐子,一开始第 个筐子里有 个球。
小亮每次可以选择一个 (),满足该筐子至少有两个球。将一个球取出放到左侧()的任一筐子,将一个球取出放到右侧()的任一筐子。可以进行任意次操作。
小亮希望最后第 个筐子有 个球,他想知道是否存在合法的操作方案能达到他的目标。
本题的每个测试点有多组数据。
第一行一个正整数 表示数据组数。
对每组数据,第一行一个正整数 表示筐子数量。
对每组数据,第二行 个正整数,表示初始球数 。
对每组数据,第三行 个正整数,表示目标球数 。
对每组数据,输出一行一个字符串 YES
或 NO
表示是否存在合法的操作方案。
2
5
2 4 4 2 1
4 3 1 3 2
5
1 1 2 4 2
4 3 4 1 3
YES
NO
,,。
小亮发现他一天下来啥都没干,对自己的行为表示忏悔,并保证他以后再也不会移动超过 个筐子的球球了!(因为 个筐子他根本操作不过来)
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.
The sum of over all test cases does not exceed .
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 .
For each test case, output a single line containing YES
if it is possible to make all of the bins beautiful or NO
otherwise.
2
5
2 4 4 2 1
4 3 1 3 2
5
1 1 2 4 2
4 3 4 1 3
YES
NO
For the first test case, one possible solution is as follows:
Move one ball from bin to bin and another from bin to bin . The number of balls in each bin is now .
Move one ball from bin to bin and another from bin to bin . The number of balls in each bin is now .
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.