OI Problems   关于

#kl5960. Beautiful Bins

时间限制:2 s       空间限制:256 MiB       标签: 数学 代数 操作问题 缺题解 

算法难度等级:4       思维难度等级:10       实现难度等级:4


本题来源于:DMOPC '22 Contest 2 第五题

  • 简体中文
  • English

题目背景

由于洒水消耗的体力过大,筋疲力尽的小亮现在连最基本的数论题都解决不了了,于是他开始对着一排筐子里的球玩了起来。

题目描述

有一排 nn 个筐子,一开始第 ii 个筐子里有 aia_i 个球。

小亮每次可以选择一个 ii1<i<n1 < i < n),满足该筐子至少有两个球。将一个球取出放到左侧(<i< i)的任一筐子,将一个球取出放到右侧(>i> i)的任一筐子。可以进行任意次操作。

小亮希望最后第 ii 个筐子有 bib_i 个球,他想知道是否存在合法的操作方案能达到他的目标。

输入格式

本题的每个测试点有多组数据。

第一行一个正整数 TT 表示数据组数。

对每组数据,第一行一个正整数 nn 表示筐子数量。

对每组数据,第二行 nn 个正整数,表示初始球数 aia_i

对每组数据,第三行 nn 个正整数,表示目标球数 bib_i

输出格式

对每组数据,输出一行一个字符串 YESNO 表示是否存在合法的操作方案。

样例输入输出

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

数据范围

1T1061\leq T\leq 10^63n, n1063\leq n,\ \sum n\leq 10^61ai, bi1091\leq a_i,\ b_i\leq 10^9

后记

小亮发现他一天下来啥都没干,对自己的行为表示忏悔,并保证他以后再也不会移动超过 55 个筐子的球球了!(因为 10510^5 个筐子他根本操作不过来)

NN bins are lined up in a row, numbered 11 to NN from left to right. Bin ii initially contains AiA_i balls, and it is considered beautiful if it contains BiB_i balls. In one move, you may pick a bin ii (1<i<N1 < i < N) with at least 22 balls, move one ball from bin ii to any bin on its left, and move another ball from bin ii 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 TT test cases.

Constraints

1T1061\leq T\leq 10^6

3N1063\leq N\leq 10^6

1ai, bi1091\leq a_i,\ b_i\leq 10^9

The sum of NN over all test cases does not exceed 10610^6.

Input Specification

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

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

The second line of each test case contains NN integers A1, A2, , ANA_1,\ A_2,\ \cdots,\ A_N.

The third line of each test case contains NN integers B1, B2, , BNB_1,\ B_2,\ \cdots,\ B_N.

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

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

Explanation for Sample

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

  1. Move one ball from bin 33 to bin 11 and another from bin 33 to bin 44. The number of balls in each bin is now [3, 4, 2, 3, 1][3,\ 4,\ 2,\ 3,\ 1].

  2. Move one ball from bin 22 to bin 11 and another from bin 22 to bin 33. The number of balls in each bin is now [4, 2, 3, 3, 1][4,\ 2,\ 3,\ 3,\ 1].

  3. Move one ball from bin 33 to bin 22 and another from bin 33 to bin 55. The number of balls in each bin is now [4, 3, 1, 3, 2][4,\ 3,\ 1,\ 3,\ 2].

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