This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;
template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }
mt19937 rng((uint64_t) new char);
int solve(){
int n, k;
cin >> n >> k;
int z = n + k;
vec <int> a(z);
for (auto &i: a) cin >> i;
auto check = [&](int x){
int pl = 0, pr = z - 1;
vec <int> ans;
while(pl < pr && sz(ans) < n){
if (a[pl] + a[pr] == x){
ans.push_back(a[pl]);
ans.push_back(a[pr]);
++pl, --pr;
}
else if (a[pl] + a[pr] < x) ++pl;
else --pr;
}
if (sz(ans) == n){
sort(all(ans));
for (auto &i: ans) cout << i << " ";
exit(0);
}
};
if (n < k){
for (int i = 0; i < z; ++i){
for (int j = i + 1; j < z; ++j){
check(a[i] + a[j]);
}
}
assert(false);
}
int j = rng() % z;
int l = max(0, z - j - k - 2), r = min(z, z - j + k + 2);
for (int i = l; i < r; ++i){
check(a[i] + a[j]);
}
return 0;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tst = 1; //cin >> tst;
while(tst--) solve();
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... |