[Solution] Sanae and Giant Robot Codeforces Solution | Codeforces Problem Solution 2022
The state of a robot can be represented by an array of integers of length . Initially, the robot is at state . She wishes to turn it into state .
As a great programmer, Sanae knows the art of copy-and-paste. In one operation, she can choose some segment from given segments, copy the segment from and paste it into the same place of the robot, replacing the original state there. However, she has to ensure that the sum of does not change after each copy operation in case the robot go haywire. Formally, Sanae can choose segment and assign () if does not change after the operation.
Determine whether it is possible for Sanae to successfully turn the robot from the initial state to the desired state with any (possibly, zero) operations.
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers , (, ) — the length of , and the number of segments.
The second line contains intergers () — the initial state .
The third line contains intergers () — the desired state .
Then lines follow, the -th line contains two intergers () — the segments that can be copy-pasted by Sanae.
It is guaranteed that both the sum of and the sum of over all test cases does not exceed .
For each test case, print "YES" (without quotes) if can be turned into , or "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
No comments:
Post a Comment