GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 7 June 2022

[Solution] Array Decrements Codeforces Solution


B. Array Decrements
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

  • apply a decrement to each non-zero element of the array, that is, replace the value of each element ai such that ai>0 with the value ai1 (1in). If ai was 0, its value does not change.

Determine whether Kristina can get an array b from an array a in some number of operations (probably zero). In other words, can she make ai=bi after some number of operations for each 1in?

Solution Click Below:-  CLICK HERE

For example, let n=4a=[3,5,4,1] and 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];
  • after the second use of the operation she gets a=[1,3,2,0].

Thus, in two operations, she can get an array b from an array a.

Input

The first line of the input contains an integer t (1t104) —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 n (1n5104).

The second line of each test case contains exactly n non-negative integers a1,a2,,an (0ai109).

The third line of each test case contains exactly n non-negative integers b1,b2,,bn (0bi109).

It is guaranteed that the sum of n values over all test cases in the test does not exceed 2105.

Output

For each test case, output on a separate line:

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

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

No comments:

Post a Comment