Functional Array ( DSA INTERVIEW PREPARATION PROBLEMS AND SOLUTIONS )

 The functional array of an array 

A=[A1,A2,,AN] is the array fA of size N1, where fAi=Ai+1Ai for 1i<N. For example, if A=[2,3,9,11] then fA=[1,6,2].

You are given two arrays B=[B1,B2,,BN] and Z=[Z1,Z2,,ZM] of length N and M respectively. Find out whether there exists an array A such that:

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

  • 1T105
  • 1N105
  • 1M105
  • 0Bi105
  • 0Zi105
  • The sum of N over all test cases does not exceed 105
  • The sum of M over all test cases does not exceed 105

Subtasks

Subtask #1 (5 points):

  • 1M10
  • 1N103
  • 0Bi103
  • 0Zi103
  • The sum of M over all test cases does not exceed 100

Subtask #2 (40 points):

  • 1M103
  • 1N103
  • 0Bi103
  • 0Zi103
  • The sum of M over all test cases does not exceed 103

Subtask #3 (55 points):

  • Original constraints

Code: click
Previous
Next Post »