#include <bits/stdc++.h>
//#include "grader.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
//#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
//#define sort(a) sort(a.begin(), a.end())
#define all(a) a.begin(), a.end()
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 5000000000000000000
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(1488);
ll randll(ll l, ll r){
return uniform_int_distribution<ll>(l, r)(rng);
}
int main() {
speed;
srand(time(0));
ll n, k;
cin >> n >> k;
vll a(n+k);
for (int i = 0; i < n+k; i ++) {
cin >> a[i];
}
sort(all(a));
set<ll> s1;
ll l = min(n+k, k*2);
ll r = max((ll)0, n-k);
vll c;
for (int i = 0; i < min(n+k, k*2); i ++) {
c.pb(i);
}
random_shuffle(all(c));
for (int i : c) {
for (int j = n+k-1; j >= max((ll)0, n-k); j --) {
if (i == j) break;
/*if (s1.find(a[i]+a[j]) != s1.end()) continue;
s1.insert(a[i]+a[j]);*/
vbool us(n+k, 0);
ll k1 = 0;
ll s = a[i]+a[j];
ll l = 0, r = n+k-1;
while (r > l) {
while (l < r && a[l]+a[r] > s) {
r --;
}
if (l >= r) break;
if (a[l]+a[r] == s) {
k1 += 2;
us[l] = 1;
us[r] = 1;
r --;
}
l ++;
}
if (k1 == n) {
for (int i1 = 0; i1 < n+k; i1 ++) {
if (us[i1]) cout << a[i1] << ' ';
}
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... |