이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 150407;
int n, k;
int a[N];
void find_ans(int s) {
int pos = n + k - 1;
int cnt = 0;
for (int i = 0; i < n + k; ++i) {
while (pos > i && a[pos] + a[i] > s)
--pos;
if (pos <= i)
break;
if (a[i] + a[pos] == s) {
++cnt;
--pos;
}
}
if (2 * cnt >= n) {
pos = n + k - 1;
vector<int> left, right;
for (int i = 0; i < n + k; ++i) {
while (pos > i && a[pos] + a[i] > s)
--pos;
if (pos <= i)
break;
if (a[i] + a[pos] == s) {
left.push_back(a[i]);
right.push_back(a[pos]);
--pos;
}
}
reverse(right.begin(), right.end());
for (int &x : left)
cout << x << " ";
for (int &x : right)
cout << x << " ";
exit(0);
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n + k; ++i)
cin >> a[i];
sort(a, a + n + k);
vector<int> sums;
if (n + k <= 4 * k) {
for (int i = 0; i < n + k; ++i) {
for (int j = 0; j < i; ++j) {
sums.push_back(a[i] + a[j]);
}
}
} else {
map<int, int> mp;
for (int i = 0; i < 2 * k; ++i) {
for (int j = n + k - 1; j >= n + k - 2 * k; --j)
++mp[a[i] + a[j]];
}
for (auto [s, cnt] : mp) {
if (cnt >= k)
sums.push_back(s);
}
}
for (int &s : sums)
find_ans(s);
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... |