nwerc-2016/full/F.cpp

39 lines
947 B
C++

#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
long f(vector<long>& l)
{
long m = 0; set<long, greater<long>> s = {0};
for(auto x : l) {
// cerr << "x = " << x << endl;
if (s.count(x) == 0) {
m = max(m, min(*s.begin(), x));
s.insert(x);
} else {
s.erase(x);
m = max(m, min(*s.begin(), x));
}
// cerr << "m = " << m << endl;
}
return m;
}
int main()
{
long n; cin >> n; vector<long> l1(n), l2(n);
for (long i = 0; i < n; ++i) cin >> l1[i];
for (long i = 0; i < n; ++i) cin >> l2[i];
set<long> s2(begin(l2), end(l2));
set<long, greater<long>> s; vector<long> l1_, l2_;
for (auto x : l1) if (s2.count(x) == 1) s.insert(x);
for (auto x : l1) if (s.count(x) == 0) l1_.push_back(x);
for (auto x : l2) if (s.count(x) == 0) l2_.push_back(x);
long m = *s.begin();
cout << max(m, max(f(l1_), f(l2_))) << endl;
}