P18500 [CodeChef] FUNARR
提高+
题目描述

Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.

The functional array of an array $A = [A_{1}, A_{2}, \dots, A_{N}]$ is the array fA of size N-1, where fA_{i} = A_{i+1} - A_{i} for 1≤ i < N. For example, if A = [2, 3, 9, 11] then fA = [1, 6, 2].

You are given two arrays $B = [B_{1}, B_{2}, \dots, B_{N}]$ and $Z = [Z_{1}, Z_{2}, \dots, Z_{M}]$ of length N and M respectively. Find out whether there exists an array A such that:
B is a [subsequence] of A, and
fA is a subsequence of Z

Print "YES" (without quotes) if such an array A exists, and "NO" otherwise.

------ Input Format ------

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case contains three lines of input.
  • The first line contains two integers N and M - the lengths of B and Z respectively.
  • The second line contains $N space-separated integers B_{1}, B_{2}, \dots, B_{N}$; the elements of B.
  • The third line contains $M space-separated integers Z_{1}, Z_{2}, \dots, Z_{M}$; the elements of Z.

------ Output Format ------

For each test case, output a single line containing one word - either "YES" or "NO". You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ M ≤ 10^{5}$
$0 ≤ B_{i} ≤ 10^{5}$
$0 ≤ Z_{i} ≤ 10^{5}$
- The sum of $N$ over all test cases does not exceed $10^{5}$
- The sum of $M$ over all test cases does not exceed $10^{5}$

------ subtasks ------

Subtask #1 (5 points):
$1≤ M ≤ 10$
$1≤ N ≤ 10^{3}$
$0≤ B_{i} ≤ 10^{3}$
$0≤ Z_{i} ≤ 10^{3}$
The sum of $M$ over all test cases does not exceed $100$

Subtask #2 (40 points):
$1≤ M ≤ 10^{3}$
$1≤ N ≤ 10^{3}$
$0≤ B_{i} ≤ 10^{3}$
$0≤ Z_{i} ≤ 10^{3}$
The sum of $M$ over all test cases does not exceed $10^{3}$

Subtask #3 (55 points):
Original constraints

----- Sample Input 1 ------
2
2 2
2 3
1 1
2 2
2 4
1 3
----- Sample Output 1 ------
YES
NO
----- explanation 1 ------
Test case 1:

$A = [1, 2, 3]$ is one possible array.
- $B = [2, 3]$ is a subsequence of $A$
- $fA = [1, 1]$ is a subsequence of $Z = [1, 1]$.

Test case 2:

It can be shown that no array $A$ can both contain $B = [2, 4]$ as a subsequence and also have $fA$ be a subsequence of $Z = [1, 3]$

输入格式

见题面

输出格式

见题面

样例输入
2 2 2 2 3 1 1 2 2 2 4 1 3
样例输出
YES NO