题意;给你一个a数组和b数组,问你能不能通过任意次操作使a得到b
对于这个操作的介绍是如果,那么
可以选择+1,特殊的在i为n时,如果
可以选择+1.
思路;因为a数组要经过变换得到b数组,而如果,那么如果
,那么
就不能通过
将
变成
(因为
最大也只能是
),然后直接flag=true,
最后直接判断输出即可。
代码
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;
const int N=1000000+100;
int n ,m,h;
int a[N],b[N];
int main()
{
int t;
sc_int(t);
while(t--)
{
sc_int(n);
bool flag=0;
for(int i =1;i<=n;i++)
sc_int(a[i]);
for(int i=1;i<=n;i++){
sc_int(b[i]);
if(a[i]>b[i])flag=1;
}
for(int i =1;i<n;i++)
{
if(b[i]-b[i+1]>1)
{
if(b[i]!=a[i])
flag=1;
}
}
if(b[n]-b[1]>1)
{
if(b[n]!=a[n])
flag=1;
}
if(flag)cout<<"NO\n";
else cout<<"YES\n";
}
return 0;
}