-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
75 lines (68 loc) · 1.69 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
int main()
{
int tc;
cin>>tc;
vector< int > baseArr;
vector< int > updateArr;
while(tc--)
{
int n;
cin>>n;
map< int , int > mp;
vector< int > freq;
baseArr.resize(n);
updateArr.resize(n);
for(int i = 0; i < n ; i++)
{
cin>>baseArr[i];
}
baseArr[-1] = 0;
baseArr[n+1] = 0;
//cout<<" Ok" <<endl;
for(int i = 0; i < n ; i++)
{
cin>>updateArr[i];
}
updateArr[-1] = 0;
updateArr[n+1] = 0;
//cout<<" Ok" <<endl;
for(int i = 0; i < n ; i++)
{
if(baseArr[i] != updateArr[i])
{
freq.push_back(i);
}
}
int cnt = 0;
// for(int i =0; i<freq.size(); i++)
// {
// cout<<freq[i]<<" ";
// }
// cout<<"------------------"<<endl;
for(int i =0; i<freq.size(); i++)
{
//cout<<freq[i]<<endl;
if(updateArr[freq[i]] >= 0 && (baseArr[freq[i] - 1] != 0))
{
if((baseArr[freq[i]] + baseArr[freq[i] - 1])>= 0 )
cnt++;
}
if(updateArr[freq[i]] < 0 && (baseArr[freq[i] - 1] != 0))
{
if((baseArr[freq[i]] + baseArr[freq[i] - 1]) < 0 )
cnt++;
}
}
if(cnt != freq.size())
{
cout<<"NO"<<endl;
}
else
cout<<"YES"<<endl;
freq.clear();
updateArr.clear();
baseArr.clear();
}
}