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>
using namespace std;
constexpr int NMAX = 2e5;
int N, K;
int a[NMAX];
bool ok = 0;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
for (int i = 1; i <= N+K; ++ i ) {
cin >> a[i];
}
sort(a+1, a+N+K+1);
for (int i = 1; i <= K+1; ++ i ) {
for (int j = N+K; j >= N; -- j ) {
int cnt_per = 0;
int st = i, dr = j;
vector <int> st_s, dr_s;
while (st < dr && (dr - st + 1) / 2 + cnt_per >= N/2 && cnt_per < N/2) {
if (a[st] + a[dr] == a[i] + a[j]) {
st_s.push_back(st);
dr_s.push_back(dr);
++ st;
-- dr;
cnt_per++;
}
else if (a[st] + a[dr] > a[i] + a[j])
-- dr;
else
++ st;
}
if (cnt_per == N/2) {
ok = 1;
for (auto it : st_s)
cout << a[it] << " ";
for (int i = dr_s.size() - 1; i >= 0; -- i )
cout << a[dr_s[i]] << " ";
break;
}
}
if (ok == 1) break;
}
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... |