#include <bits/stdc++.h>
using namespace std;
int TC = 0;
#define int long long
const int INF = (int) 1e18;
const int MOD1 = 1000000007;
const int MOD2 = 998244353;
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define size(v) (int) v.size()
#define YN(x) cout << (x ? "YES\n" : "NO\n");
#define yn(x) cout << (x ? "yes\n" : "no\n");
#define left node * 2, l, (l + r) / 2
#define right node * 2 + 1, (l + r) / 2 + 1, r
#define mark() cout << "[✓] reached line " << __LINE__ << "\n"
#define debug(x) cout << #x << " = " << x << "\n";
set<int> st;
bool check(int val, int n) {
int cnt = 0;
// cout << val << endl;
for (auto x : st) {
if (st.find(val - x) != st.end()) {
// cout << x << ' ';
cnt++;
}
}
// cout << endl;
return cnt >= n;
}
void print(int val, int n) {
vector<int> ans;
for (int x : st) {
if (st.find(val - x) != st.end()) ans.push_back(x);
}
for (int i = 0; i < size(ans); i++) {
if (i < n / 2 || i > size(ans) - n / 2 - 1) {
cout << ans[i] << ' ';
}
}
cout << endl;
}
void solve() {
int n, k;
cin >> n >> k;
int x[n + k];
for (int i = 0; i < n + k; i++) {
cin >> x[i];
st.insert(x[i]);
}
sort(x, x + n);
for (int i = 0; i <= k; i++) {
for (int j = n - 1; j < n + k; j++) {
if (check(x[i] + x[j], n)) {
// cout << x[i] + x[n + k - 1 - i] << endl;
print(x[i] + x[j], n);
return;
}
}
}
}
signed main(){
IOS;
int q = 1;
// cin >> q;
while(++TC <= q) {
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... |