Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- //#include <ext/pb_ds/assoc_container.hpp>
- //#include <ext/pb_ds/tree_policy.hpp>
- //#include <Rescue.h>
- using namespace std;
- //using namespace __gnu_pbds;
- #define INF (1<<30)
- #define INFll (1ll<<62)
- #define F first
- #define S second
- #define MOD 1000000007
- #define mkp(a, b) make_pair(a, b)
- #define MAX(a, b) (((a) >= (b)) ? (a) : (b))
- #define MIN(a, b) (((a) <= (b)) ? (a) : (b))
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- #ifndef LOCAL
- #define cerr if(false) cerr
- #endif // LOCAL
- #define FOR(I, A, B) for(int (I) = (A); (I) < (B); (I)++)
- #define ROF(I, A, B) for(int (I) = (A); (I) >= (B); (I)--)
- #define SQR(A) 1ll*(A)*(A)
- //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const char array_sep[] = " ";
- const char array_end[] = "";
- const char pair_sep[] = " ";
- const char pair_end[] = "";
- const char map_sep[] = "->";
- const char map_end[] = "\n";
- const int dx[] = {-1, 0, 1, 0};
- const int dy[] = {0, 1, 0, -1};
- const int ddx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
- const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};
- template<typename A> ostream & operator<<(ostream & os, const vector<A> & x)
- {
- for(int i = 0; i < x.size(); i++)
- os << x[i] << array_sep;
- os << array_end;
- return os;
- }
- template<typename A, typename B> ostream & operator<<(ostream & os, const pair<A, B> & x)
- {
- os << x.first << pair_sep << x.second << pair_end;
- return os;
- }
- template<typename A> istream & operator>>(istream & is, vector<A> & x)
- {
- for(int i = 0; i < x.size(); i++)
- is >> x[i];
- return is;
- }
- template<typename A, typename B> istream & operator>>(istream & is, pair<A, B> & x)
- {
- is >> x.first >> x.second;
- return is;
- }
- //#define cerr if(0)cerr
- //
- //template<typename _key, typename _val> ostream & operator<<(ostream & os, map<_key, _val> & mp)
- //{
- // for(auto it : mp) // not for C++98 or earlier
- // os << it->F << map_sep << it->S << map_end;
- // return os;
- //}
- //
- //template<typename _key, typename _val> ostream & operator<<(ostream & os, unordered_map<_key, _val> & mp)
- //{
- // for(auto it : mp) // not for C++98 or earlier
- // os << it->F << map_sep << it->S << map_end;
- // return os;
- //}
- //
- //template<typename _key, typename _val> ostream & operator<<(ostream & os, set<_key> & st)
- //{
- // for(auto& it: st) // not for C++98 or earlier
- // os << it << endl;
- // return os;
- //}
- //
- //template<typename _key, typename _val> ostream & operator<<(ostream & os, unordered_set<_key> & st)
- //{
- // for(auto& it: st) // not for C++98 or earlier
- // os << it << endl;
- // return os;
- //}
- template<typename _response> void die(_response ans)
- {
- cout << ans << endl;
- exit(0);
- }
- int main()
- {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- // freopen("errlog.log", "w", stderr);
- ios_base::sync_with_stdio(0);
- // cout << fixed << setprecision(3);
- #else // LOCAL
- // freopen("gcd-xor.in", "r", stdin);
- // freopen("gcd-xor.out", "w", stdout);
- ios_base::sync_with_stdio(0);
- // cout << fixed << setprecision(3);
- #endif // LOCAL
- int n;
- vector<int> a;
- vector<pair<int, int > > ans;
- cin >> n;
- a.resize(n << 1);
- cin >> a;
- set<pair<pair<int, int >, pair<int, int > > > st;
- vector<int> l_lnk(n << 1, -1);
- vector<int> r_lnk(n << 1, -1);
- sort(a.begin(), a.end());
- for(int i = 0; i < (n << 1); i++)
- {
- if(i) l_lnk[i] = i-1;
- if(i != (n << 1) - 1) r_lnk[i] = i+1;
- if(i) st.insert({{a[i] - a[i-1], -a[i]-a[i-1]}, {i-1, i}});
- }
- while(true)
- {
- // cerr << "# " << i << " " << st.size() << " ";
- if(st.empty()) break;
- auto top = *st.begin(); st.erase(st.begin());
- int l = top.S.F;
- int r = top.S.S;
- cerr << top << endl;
- cerr << "\t#" << l_lnk[l] << " " << r_lnk[r] << endl;
- ans.push_back(mkp(a[top.S.F], a[top.S.S]));
- if(l_lnk[l] == -1 && r_lnk[r] == -1) continue;
- if(l_lnk[l] == -1 && r_lnk[r] != -1)
- {
- l_lnk[r_lnk[r]] = -1;
- st.erase({{a[r_lnk[r]] - a[r], -a[r]-a[r_lnk[r]]}, {r, r_lnk[r]}});
- continue;
- }
- if(l_lnk[l] != -1 && r_lnk[r] == -1)
- {
- r_lnk[l_lnk[l]] = -1;
- st.erase({{a[l] - a[l_lnk[l]], -a[l]-a[l_lnk[l]]}, {l_lnk[l], l}});
- continue;
- }
- if(l_lnk[l] != -1 && r_lnk[r] != -1)
- {
- r_lnk[l_lnk[l]] = r_lnk[r];
- l_lnk[r_lnk[r]] = l_lnk[l];
- st.erase({{a[l] - a[l_lnk[l]], -a[l]-a[l_lnk[l]]}, {l_lnk[l], l}});
- st.erase({{a[r_lnk[r]] - a[r], -a[r]-a[r_lnk[r]]}, {r, r_lnk[r]}});
- st.insert({{a[r_lnk[r]] - a[l_lnk[l]], -a[l_lnk[l]]-a[r_lnk[r]]}, {l_lnk[l], r_lnk[r]}});
- continue;
- }
- // cout << st.size() << endl;
- }
- for(int i = 0; i < n; i++)
- cout << max(ans[i].F, ans[i].S) << " ";
- cout << endl;
- for(int i = 0; i < n; i++)
- cout << min(ans[i].F, ans[i].S) << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement