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;
const int maxn = 3e5 + 5;
int arr[maxn];
int n, m;
vector<int> ans;
int Find(int x, bool key) {
int ret = 0;
for (int i = 1, j = n; i < j; i++) {
while (i < j && arr[i] + arr[j] > x) j--;
if (i < j && arr[i] + arr[j] == x) {
ret += 2;
if (key) {
ans.emplace_back(arr[i]);
ans.emplace_back(arr[j]);
if (ret == n - m) break;
}
}
}
return ret;
}
void solve() {
cin >> n >> m;
n += m;
for (int i = 1; i <= n; i++) cin >> arr[i];
int lim = min(n>>1, m*3);
for (int i = 1; i <= lim && ans.empty(); i++)
for (int j = n; j >= n - lim; j--)
if (Find(arr[i] + arr[j], false) >= n-m) {
Find(arr[i] + arr[j], true);
break;
}
sort(ans.begin(), ans.end());
for (int i = 0, len = ans.size(); i < len; i++)
cout << ans[i] << " \n"[i == len-1];
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
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... |