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;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, k, A[200005];
void solve(){
cin >> n >> k;
assert(n <= 150000);
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--){
if(i - 1 + n + k - j > k)continue;
int l = i + 1, r = j - 1, cnt = 1, tar = A[i] + A[j];
while(l <= r){
while(r >= l && A[l] + A[r] > tar)r--;
if(r <= l || cnt + (r - l + 1) / 2 < n / 2)break;
if(A[l] + A[r] == tar)cnt++, r--;
l++;
}
//cerr << i << ' ' << j << ' ' << cnt << '\n';
if(cnt >= n / 2){
vector <int> v;
v.push_back(A[i]); v.push_back(A[j]);
l = i + 1, r = j - 1, tar = A[i] + A[j];
while(l <= r){
while(r >= l && A[l] + A[r] > tar)r--;
if(r <= l)break;
if(A[l] + A[r] == tar && v.size() < n)v.push_back(A[l]), v.push_back(A[r]);
l++;
}
sort(v.begin(), v.end());
for(auto a : v)cout << a << ' ';
cout << '\n';
return;
}
}
}
//assert(0);
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:39:40: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
39 | if(A[l] + A[r] == tar && v.size() < n)v.push_back(A[l]), v.push_back(A[r]);
| ~~~~~~~~~^~~
tabletennis.cpp: At global scope:
tabletennis.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main(){
| ^~~~
# | 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... |