CF 797, got stuck on E and had to leave, went pretty well
This commit is contained in:
66
codeforces/rounds/797/b.cpp
Normal file
66
codeforces/rounds/797/b.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void test_case(int tc){
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vector<int> a(n);
|
||||
vector<int> b(n);
|
||||
|
||||
for (size_t i = 0; i < n; i++){
|
||||
cin >> a[i];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n; i++){
|
||||
cin >> b[i];
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
|
||||
int exactdif = INT32_MAX;
|
||||
int hightestdif = 0;
|
||||
bool onlyzeroes = true;
|
||||
|
||||
for(size_t i = 0; i < n; ++i){
|
||||
auto ax = a[i], bx = b[i];
|
||||
auto d = ax - bx;
|
||||
|
||||
if(bx == 0){
|
||||
hightestdif = max(hightestdif, d);
|
||||
} else {
|
||||
onlyzeroes = false;
|
||||
if(exactdif == INT32_MAX){
|
||||
exactdif = d;
|
||||
} else if(exactdif != d){
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(hightestdif > exactdif){
|
||||
result = false;
|
||||
}
|
||||
|
||||
cout << (result || onlyzeroes ? "YES" : "NO") << '\n';
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
}
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user