#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
constexpr int MAX = 3e+8 + 1, INF = 2e+9, MOD = 1e+9 + 7, K = 31;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get(int l, int r) {
int sz = r - l + 1;
return l + rng() % sz;
}
bool solve(int n, int k, vector <int> &v, int e) {
for (int z1 = max(0, e - k); z1 <= min(n-1, e + k); z1++) {
int z = n - z1 - 1;
if (e == z) continue;
int s = v[e] + v[z];
unordered_map <int, int> m;
for (int &i : v) m[i]++;
vector <int> q;
for (int &i : v) {
if (i == s - i) continue;
q.pb(s-i);
}
int x = q.size() - 1;
int res=0;
for (int &i : v) {
while (x > 0 && q[x] < i) x--;
if (q[x] == i) res++;
}
if (res >= n-k) {
x = q.size() - 1;
res = 0;
vector <int> ans;
for (int &i : v) {
if (res == n - k) break;
while (x > 0 && q[x] < i) x--;
if (q[x] == i) {
res+=2;
ans.pb(i);
ans.pb(s-i);
}
}
sort(all(ans));
for (int &i : ans) cout << i << ' ';
return 1;
}
}
return 0;
}
void _() {
int n, k;
cin >> n >> k;
n += k;
vector <int> v(n);
for (int &i : v) cin >> i;
sort(all(v));
vector <int> id;
for (int i = 0; i < n; i++) id.pb(i);
for (int i = 0; i < n; i++) {
swap(id[i], id[rng() % n]);
}
for (int &i : id) {
if (solve(n, k, v, i)) break;
}
}
signed main() {
GOOD_LUCK
int tests=1;
// cin >> tests;
for (int i=1; i <= tests; i++) {
_();
cout << endl;
}
return 0;
}
| # | 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... |