#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;
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++;
l++;
r--;
}
//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++; r--;
}
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
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 |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
860 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
4272 KB |
Output is correct |
2 |
Correct |
31 ms |
4300 KB |
Output is correct |
3 |
Correct |
27 ms |
4304 KB |
Output is correct |
4 |
Correct |
30 ms |
4196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
41 ms |
4272 KB |
Output is correct |
3 |
Runtime error |
18 ms |
2804 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
23 ms |
2900 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |