Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1408A.cpp #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions 1408A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define mod 1000000007
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
bool compare(int a, int b) {
return a > b;
}
int32_t main() {
fio;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[3][n];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
vector<int>v;
for (int i = 0; i < n - 1; i++) {
int max_ele = max(a[0][i], max(a[2][i], a[1][i]));
int min_ele = min(a[0][i], min(a[2][i], a[1][i]));
if (i == 0) {
v.push_back(max_ele);
continue;
}
else if (i % 2 == 0) {
if (max_ele != v[i - 1]) {
v.push_back(max_ele);
}
else {
v.push_back(min_ele);
}
}
else {
if (min_ele != v[i - 1]) {
v.push_back(min_ele);
}
else {
v.push_back(max_ele);
}
}
}
int op1 = max(a[0][n - 1], max(a[2][n - 1], a[1][n - 1]));
int op2 = min(a[0][n - 1], min(a[2][n - 1], a[1][n - 1]));
if (op1 != v[0] and op1 != v[n - 2]) {
v.push_back(op1);
}
else if (op2 != v[0] and op2 != v[n - 2]) {
v.push_back(op2);
}
else {
for (int i = 0; i < 3; i++) {
if (a[i][n - 1] != op1 and a[i][n - 1] != op2) {
v.push_back(a[i][n - 1]);
}
}
}
for (auto p : v) {
cout << p << " ";
}
cout << endl;
}
}