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/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen(".inp", "r"))
assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
using namespace chrono;
auto start = steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = steady_clock::now();
cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
const int N = 2e5;
int n, k, a[N];
bool check(int sum) {
int cnt = 0;
vector<int> l, r;
// cout << sum << '\n';
for (int i = 1, j = n + k; i < j; i++) {
while (j > i && a[j] + a[i] > sum) j --;
if (j > i && a[j] + a[i] == sum) {
cnt ++;
l.push_back(a[i]);
r.push_back(a[j]);
}
}
if (cnt == n / 2) {
reverse(r.begin(), r.end());
for (int i : l)
cout << i << ' ';
for (int i : r)
cout << i << ' ';
}
return cnt == n / 2;
}
void Hollwo_Pelw(){
cin >> n >> k;
for (int i = 1; i <= n + k; i++)
cin >> a[i];
map<int, int> cnt;
if (4 * k > n) {
for (int i = 1; i <= n + k; i++)
for (int j = i + 1; j <= n + k; j++)
cnt[a[i] + a[j]] ++;
for (auto [v, c] : cnt) {
if (c >= n / 2)
if (check(v)) return;
}
}
for (int i = 1; i <= 2 * k; i++) {
for (int j = n - k + 1; j <= n + k; j++) {
cnt[a[i] + a[j]] ++;
}
}
for (auto [v, c] : cnt) {
if (c >= k)
if (check(v)) return;
}
}
# | 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... |