当前位置:网站首页>6.26cf simulation match B: solution to array reduction problem
6.26cf simulation match B: solution to array reduction problem
2022-07-04 18:53:00 【bj_ hacker】
6.26CF Simulation game B: Array reduction problem solution
Title Description
link
CF Simulation game B: Array reduction
A word description
B. Array reduction
time limit per test1 s.
memory limit per test256 MB
inputstandard input
outputstandard 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:
Kristina There are two arrays a and b, Each one contains n Nonnegative integers . She can treat a The array performs the following operations any number of times :
For each non 0 Element minus 1, That is, all greater than 0 Of ai Replace with ai−1 (1≤i≤n). If ai yes 0, Its value remains unchanged .
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 1≤i≤n?
Judge Kristina Whether it can pass several times ( It can be 0 Time ) Operation will a The array becomes b Array ? let me put it another way , Can she let ai=bi For any 1≤i≤n establish ?
For example, let n=4, a=[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].
For example, for n=4, a=[3,5,4,1] and b=[1,3,2,0], She can operate twice :
After the first operation a=[2,4,3,0];
After the second operation a=[1,3,2,0].
Thus, in two operations, she can get an array b from an array a.
So after two operations , She can put a become b.
Input
The first line of the input contains an integer t (1≤t≤104) —the number of test cases in the test.
The first line contains an integer t (1≤t≤104) — Number of representative test data groups .
The descriptions of the test cases follow.
The description of each group of data is as follows .
The first line of each test case contains a single integer n (1≤n≤5⋅104).
The first line contains an integer n (1≤n≤5⋅104).
The second line of each test case contains exactly n non-negative integers a1,a2,…,an (0≤ai≤109).
The second line contains n Nonnegative integers a1,a2,…,an (0≤ai≤109).
The third line of each test case contains exactly n non-negative integers b1,b2,…,bn (0≤bi≤109).
The third line contains n Nonnegative integers b1,b2,…,bn (0≤bi≤109).
It is guaranteed that the sum of n values over all test cases in the test does not exceed 2⋅105.
Data assurance Of all test data n The sum does not exceed 2⋅105.
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 yEs, yes, Yes and YES will be recognized as a positive response).
For each group of test data , Output YES perhaps NO.
Example
inputCopy
6
4
3 5 4 1
1 3 2 0
3
1 2 1
0 1 0
4
5 3 7 2
1 1 1 1
5
1 2 3 4 5
1 2 3 4 6
1
8
0
1
4
6
outputCopy
YES
YES
NO
NO
YES
NO
Note
The first test case is analyzed in the statement.
For the first set of test data , It has been analyzed in the problem description .
In the second test case, it is enough to apply the operation to array a once.
For the second set of test data , One operation is enough .
In the third test case, it is impossible to get array b from array a.
For the third set of test data , Cannot from a become b.
Topic analysis
- This question is complex and has a lot of data , Point by point analysis
- First judgement b[i]>a[i] As long as there is one NO Next group
- b[i] Is full of 0,YES Next group
- b[i]!=0 Of a[i]-b[i] There is a difference NO Next group
- b[i]==0 Of a[i]-b[i]>(4.)NO Next group , otherwise YES Next group
Code implementation
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e4+10;
int t,n,cnt;
int a[maxn],b[maxn];
int main(){
scanf("%d",&t);
while(t--){
//2
int flag=1;
cnt=-1;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
if(b[i]!=0)flag=0;
}
if(flag){
printf("YES\n");
continue;
}
//3
flag=1;
for(int i=1;i<=n;i++){
if(b[i]>a[i]){
flag=0;
break;
}
}
if(!flag){
printf("NO\n");
continue;
}
//4
flag=1;
for(int i=1;i<=n;i++){
if(b[i]!=0){
if(cnt==-1)cnt=a[i]-b[i];
else {
if(cnt!=a[i]-b[i]){
flag=0;
break;
}
}
}
}
if(!flag){
printf("NO\n");
continue;
}
//5
flag=1;
for(int i=1;i<=n;i++){
if(b[i]==0){
if(cnt<a[i]-b[i]){
flag=0;
break;
}
}
}
if(flag)printf("YES\n");
else printf("NO\n");
}
return 0;
}
边栏推荐
- How to download files using WGet and curl
- 一、C语言入门基础
- [2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
- [system disk back to U disk] record the operation of system disk back to U disk
- Scala基础教程--20--Akka
- The controversial line of energy replenishment: will fast charging lead to reunification?
- My colleagues quietly told me that flying Book notification can still play like this
- Once the "king of color TV", he sold pork before delisting
- Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
- Angry bird design based on unity
猜你喜欢
[cloud native] what is the "grid" of service grid?
力扣刷题日记/day4/6.26
Halcon template matching
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
Li Kou brush question diary /day6/6.28
Mysql5.7 installation tutorial graphic explanation
NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
Li Kou brush question diary /day8/7.1
Digital "new" operation and maintenance of energy industry
随机推荐
Li Kou brush question diary /day2/2022.6.24
2022年字节跳动日常实习面经(抖音)
With an estimated value of 90billion, the IPO of super chip is coming
2022年全国CMMI认证补贴政策|昌旭咨询
同事悄悄告诉我,飞书通知还能这样玩
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
力扣刷题日记/day5/2022.6.27
Angry bird design based on unity
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
Load test practice of pingcode performance test
基于unity的愤怒的小鸟设计
Reptile elementary learning
Redis主从复制
项目通用环境使用说明
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
如何使用 wget 和 curl 下载文件
【210】PHP 定界符的用法
2022 national CMMI certification subsidy policy | Changxu consulting