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;
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + k);
for (int i = 0; i < n + k; i++) {
cin >> a[i];
}
for (int l = 0; l <= k; l++) {
for (int r = n - 1; r >= n - k - 1; r--) {
if (l >= r) {
continue;
}
int s = a[l] + a[r], cnt = 1;
for (int i = l + 1, j = r - 1; i < j; ) {
if (cnt + (j - i + 1) / 2 < n / 2) {
break;
}
if (a[i] + a[j] == s) {
cnt++;
i++, j--;
} else if (a[i] + a[j] > s) {
j--;
} else {
i++;
}
}
if (cnt >= n / 2) {
vector<int> ans = {a[l], a[r]};
for (int i = l + 1, j = r - 1; (int) ans.size() < n; ) {
if (a[i] + a[j] == s) {
ans.push_back(a[i]);
ans.push_back(a[j]);
i++, j--;
} else if (a[i] + a[j] > s) {
j--;
} else {
i++;
}
}
std::sort(ans.begin(), ans.end());
for (auto& x : ans) {
cout << x << " ";
}
return;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
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... |