Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- signed main() {
- cin.tie(0)->sync_with_stdio(0);
- int n; cin >> n;
- vector<int> a(n * 2);
- for (auto &i : a) cin >> i;
- sort(a.begin(), a.end());
- for (int i = 0; i + 1 < n * 2; i++) {
- int d = a.back() - a[i];
- multiset<int> s(a.begin(), a.end());
- vector<int> res;
- bool flag = false;
- for (int i = n * 2 - 1; i > 0; i--) {
- auto it = s.find(a[i]);
- if (it == s.end()) continue;
- res.push_back(a[i]);
- s.erase(it);
- it = s.find(a[i] - d);
- if (it == s.end()) {
- flag = true;
- break;
- }
- s.erase(it);
- }
- if (flag || s.size()) continue;
- cout << d << '\n';
- for (auto &i : res) cout << i << ' ';
- cout << '\n';
- return 0;
- }
- cout << -1 << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment