CF1717C.Madoka and Formal Statement
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array of integer a1,a2,…,an . In one operation you can make ai:=ai+1 if i<n and ai≤ai+1 , or i=n and ai≤a1 .
You need to check whether the array a1,a2,…,an can become equal to the array b1,b2,…,bn in some number of operations (possibly, zero). Two arrays a and b of length n are called equal if ai=bi for all integers i from 1 to n .
输入格式
The input consists of multiple test cases. The first line contains a single integer t ( 1≤t≤4⋅104 ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤2⋅105 ) – the length of the array.
The second line of each test case contains n integers a1,…,an ( 1≤ai≤109 ) – the elements of the array a .
The third line of each test case contains n integers b1,…,bn ( 1≤bi≤109 ) – the elements of the array b .
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output "YES" if you can get the array b , otherwise output "NO".
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
输入输出样例
输入#1
5 3 1 2 5 1 2 5 2 2 2 1 3 4 3 4 1 2 6 4 2 5 3 2 4 1 4 5 3 5 1 2 3 4 5 6 5 6 7 6
输出#1
YES NO NO NO YES
说明/提示
In the first test case, the array a is already equal to the array b .
In the second test case, we can't get the array b , because to do this we need to decrease a1 .
In the fifth test case, we can apply operations in order to the elements with indices 4,3,3,2,2,2,1,1,1,1 , and then get the array [5,5,5,5,5] . After that, you can apply operations in order to elements with indices 5,4,4,3,1 and already get an array [6,5,6,7,6] .