#include <bits/stdc++.h>
using namespace std;
#define break_it assert(false)
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector <int> a(n+k);
for(int i = 0; i < n +k; i ++) cin >> a[i];
function <void(int)> check=[&](int sum) {
vector <int> ans;
int l = 0, r = n + k - 1;
while(l < r) {
if(a[l] + a[r] == sum) {
ans.push_back(a[l]);
ans.push_back(a[r]);
l ++;
r --;
}else if(a[l] + a[r] > sum) {
r--;
}else l ++;
if(ans.size() == n) break;
}
if(ans.size() == n) {
sort(ans.begin(), ans.end());
for(auto i : ans) cout << i << " ";
exit(0);
}
};
function <int(vector <int>)> checkv=[](vector <int> s) {
int n = s.size();
for(int i = 0; i < n; i ++) {
int j = i + 1;
if(j >= n or n - i - 1 < 0 or n - j - 1 < 0) break;
if(s[i] + s[n-i-1] == s[j]+s[n-j-1]) continue;
return 0;
}
return 1;
};
function <void(int, int, int)> solve=[&](int start, int end, int sm = 0) {
vector <int> fors;
int sum = 0;
if(start == end and end == -1) sum = sm;
else sum = a[start] + a[end];
int none = -1;
int l = 0, r = n+k-1;
while(l < r){
if(a[l] + a[r] > sum) {
if(none != -1) return;
none = r;
r--;
}else if(a[l] + a[r] < sum) {
if(none != -1) return;
none = l;
l ++;
}
l ++;
r --;
}
if(none == -1) {
none = (n+k)/2;
}
for(int i = 0; i <= n+k-1; i ++) {
if(none == i) continue;
fors.push_back(a[i]);
}
for(auto i : fors) cout << i << " ";
exit(0);
};
if(n+k<=18) {
for(int mask = 0; mask < (1 << (n+k)); mask ++) {
if(__builtin_popcount(mask) == n) {
vector <int> v;
for(int i = 0; i < n+k; i ++) {
if((mask & (1 << i))!=0) {
v.push_back(a[i]);
}
}
if(checkv(v)) {
for(int i = 0; i < v.size(); i ++) cout << v[i] << " ";
return false;
}
}
}
return false;
}else if(k == 1) {
solve(0, n+k-1, 0);
solve(0, n+k-2, 0);
solve(1, n+k-1, 0);
}else if((k <= 20 and n <= 150000)or(n<=100 and k <=100)){
set <int> sums;
for(int i = 0; i < k+1; i ++) {
for(int j = n-k-1; j < n +k; j ++) {
sums.insert(a[i] + a[j]);
}
}
for(auto i : sums) {
check(i);
}
}else {
set <int> sums;
for(int i = k; i < 2*k; i ++) {
for(int j = n; j < n+k; j ++) {
sums.insert(a[i] + a[j]);
}
}
for(auto i : sums) {
check(i);
}
}
return false;
}
Compilation message
tabletennis.cpp: In lambda function:
tabletennis.cpp:25:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | if(ans.size() == n) break;
| ~~~~~~~~~~~^~~~
tabletennis.cpp:27:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if(ans.size() == n) {
| ~~~~~~~~~~~^~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i = 0; i < v.size(); i ++) cout << v[i] << " ";
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
716 KB |
Output is correct |
2 |
Correct |
27 ms |
3084 KB |
Output is correct |
3 |
Correct |
26 ms |
3004 KB |
Output is correct |
4 |
Correct |
25 ms |
3016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3036 KB |
Output is correct |
2 |
Correct |
31 ms |
3048 KB |
Output is correct |
3 |
Correct |
33 ms |
3040 KB |
Output is correct |
4 |
Correct |
32 ms |
3040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
9 ms |
844 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
5 ms |
840 KB |
Output is correct |
5 |
Correct |
2 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
356 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
731 ms |
3104 KB |
Output is correct |
3 |
Correct |
37 ms |
3004 KB |
Output is correct |
4 |
Correct |
97 ms |
3160 KB |
Output is correct |
5 |
Correct |
39 ms |
3092 KB |
Output is correct |
6 |
Correct |
79 ms |
3968 KB |
Output is correct |
7 |
Correct |
101 ms |
3072 KB |
Output is correct |
8 |
Correct |
90 ms |
3056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
2636 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |