CF1690B.Array Decrements

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kristina has two arrays aa and bb, each containing nn non-negative integers. She can perform the following operation on array aa any number of times:

  • apply a decrement to each non-zero element of the array, that is, replace the value of each element aia_i such that ai>0a_i \gt 0 with the value ai−1a_i - 1 (1≤i≤n1 \le i \le n). If aia_i was 00, its value does not change.

Determine whether Kristina can get an array bb from an array aa in some number of operations (probably zero). In other words, can she make ai=bia_i = b_i after some number of operations for each 1≤i≤n1 \le i \le n?

For example, let n=4n = 4, a=[3,5,4,1]a = [3, 5, 4, 1] and b=[1,3,2,0]b = [1, 3, 2, 0]. In this case, she can apply the operation twice:

  • after the first application of the operation she gets a=[2,4,3,0]a = [2, 4, 3, 0];
  • after the second use of the operation she gets a=[1,3,2,0]a = [1, 3, 2, 0].

Thus, in two operations, she can get an array bb from an array aa.

克里斯蒂娜有两个数组 aa 和 bb,每个数组都包含 nn 个非负整数。她可以对数组 aa 执行以下操作任意多次:

  • 对数组中每个非零元素执行一次减一操作,即:对每个满足 ai>0a_i > 0 的元素 aia_i(其中 1≤i≤n1 \le i \le n),将其值替换为 ai−1a_i - 1;若 ai=0a_i = 0,则其值保持不变。

请判断克里斯蒂娜是否能在若干次(可能为零次)操作后将数组 aa 变为数组 bb。换言之,是否存在某个操作次数,使得对每个 1≤i≤n1 \le i \le n 均有 ai=bia_i = b_i?

例如,设 n=4n = 4,a=[3,5,4,1]a = [3, 5, 4, 1],b=[1,3,2,0]b = [1, 3, 2, 0]。此时她可以执行两次该操作:

  • 第一次操作后,a=[2,4,3,0]a = [2, 4, 3, 0];
  • 第二次操作后,a=[1,3,2,0]a = [1, 3, 2, 0]。

因此,经过两次操作,她便可将数组 aa 变为数组 bb。

输入格式

The first line of the input contains an integer tt (1≤t≤1041 \le t \le 10^4) —the number of test cases in the test.

The descriptions of the test cases follow.

The first line of each test case contains a single integer nn (1≤n≤5⋅1041 \le n \le 5 \cdot 10^4).

The second line of each test case contains exactly nn non-negative integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \le a_i \le 10^9).

The third line of each test case contains exactly nn non-negative integers b1,b2,…,bnb_1, b_2, \dots, b_n (0≤bi≤1090 \le b_i \le 10^9).

It is guaranteed that the sum of nn values over all test cases in the test does not exceed 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤5⋅1041 \le n \le 5 \cdot 10^4)。

每个测试用例的第二行包含恰好 nn 个非负整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^9)。

每个测试用例的第三行包含恰好 nn 个非负整数 b1,b2,…,bnb_1, b_2, \dots, b_n(0≤bi≤1090 \le b_i \le 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output on a separate line:

  • YES, if by doing some number of operations it is possible to get an array bb from an array aa;
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

对于每个测试用例,在单独的一行上输出:

  • 如果可以通过执行若干次操作从数组 aa 得到数组 bb,则输出 YES;
  • 否则输出 NO。

YES 和 NO 的大小写不限(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    6
    4
    3 5 4 1
    1 3 2 0
    3
    1 2 1
    0 1 0
    4
    5 3 7 2
    1 1 1 1
    5
    1 2 3 4 5
    1 2 3 4 6
    1
    8
    0
    1
    4
    6

    输出#1

    YES
    YES
    NO
    NO
    YES
    NO

说明/提示

The first test case is analyzed in the statement.

In the second test case, it is enough to apply the operation to array aa once.

In the third test case, it is impossible to get array bb from array aa.

第一个测试用例已在题目描述中分析。

在第二个测试用例中,只需对数组 aa 执行一次该操作即可。

在第三个测试用例中,无法通过操作将数组 aa 变为数组 bb。

输入解题思路,AI测评打分。不知道怎么写?

首页