#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
using ll = long long;
ll mod = 998244353;
void solve()
{
int n, k; cin >> n >> k;
vector<int>v(n + k);
map<int, int>mp;
for (int i = 0; i < n + k; i++) {
cin >> v[i];
mp[v[i]]++;
}
sort(v.begin(), v.end());
if (k == 1) {
int aper = v[1] + v[n + k - 1], f = 0;
for (int i = 1; i < n + k; i++) {
if (v[i] + v[n + k - i] != aper) {
f = 1;
}
}
if (f == 0) {
for (int i = 1; i < n + k; i++) {
cout << v[i] << " ";
}
cout << endl;
return;
}
aper = v[0] + v[n + k - 2], f = 0;
for (int i = 0; i < n + k - 1; i++) {
if (v[i] + v[n + k - i - 2] != aper) {
f = 1;
}
}
if (f == 0) {
for (int i = 0; i < n + k - 1; i++) {
cout << v[i] << " ";
}
cout << endl;
return;
}
aper = v[0] + v[n + k - 1], f = 0;
for (int i = 0; i < n + k; i++) {
//cout << v[i] << " " << mp[v[i]] << " " << mp[aper - v[i]] << endl;
if (mp[v[i]] == 0)continue;
if (mp[aper - v[i]] == 0)f = i;
else {
mp[v[i]]--;
mp[aper - v[i]]--;
}
}
for (int i = 0; i < n + k; i++) {
if (i != f) {
cout << v[i] << " ";
}
}
cout << endl;
}
/*else if (n + k <= 18) {
for (int i = 1; i < (1 << (n + k)); i++) {
int cnt = 0;
vector<int>ans;
for (int j = 0; j < n + k; j++) {
if (i & (1 << j)) {
cnt++;
ans.push_back(v[j]);
}
}
if (cnt == n) {
int aper = ans[0] + ans[cnt - 1], f = 0;
for (int i = 0; i < cnt; i++) {
if (ans[i] + ans[cnt - i - 1] != aper) {
f = 1;
}
}
if (f == 0) {
for (int i = 0; i < cnt; i++) {
cout << ans[i] << " ";
}
cout << endl;
return;
}
}
}
}*/
else {
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= k; j++) {
if (i + j <= k) {
//if (i == 0 && j == 2)cout << "AP" << endl;
vector<int>ans;
map<int, int>mp1;
for (int ind = i + 1; ind < n + k - j; ind++) {
mp1[v[ind]]++;
}
int aper = v[i + 1] + v[n + k - j - 1], f = 0;
for (int ind = i + 1; ind < n + k - j; ind++) {
if (mp1[v[ind]] == 0)continue;
if (mp1[aper - v[ind]] == 0)continue;
if (aper - v[ind] == v[ind] && mp1[v[ind]] == 1)continue;
else {
if (ans.size() < n) {
ans.push_back(v[ind]);
ans.push_back(aper - v[ind]);
mp1[v[ind]]--;
mp1[aper - v[ind]]--;
}
}
}
if (ans.size() == n) {
sort(ans.begin(), ans.end());
for (int ind = 0; ind < ans.size(); ind++) {
cout << ans[ind] << " ";
}
cout << endl;
return;
}
}
}
}
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//signed _; cin >> _; while (_--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |