#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int n, m, k;
int a[N];
bool check(vector<int> &v){
int n = v.size();
int t = a[0] + a[n-1];
for(int l=0,r=n-1;l<r;l++,r--){
if(a[l] + a[r] != t)return false;
}return true;
}
void solve(int test_case){
int i, j;
cin >> n >> k;
m = n+k;
for(i=1;i<=m;i++){
cin >> a[i];
}
sort(a+1,a+m+1);
assert(k == 1);
if(k == 1){
bool ok = true;
int t = (a[1] + a[m-1]);
for(int l=1,r=m-1;l<r;l++,r--){
if(a[l] + a[r] != t)ok = false;
}
if(ok){
for(i=1;i<=m-1;i++)cout << a[i] << ' ' ;
cout << '\n';
return;
}
ok = true;
t = (a[2] + a[m]);
for(int l=2,r=m;l<r;l++,r--){
if(a[l] + a[r] != t)ok = false;
}
if(ok){
for(i=2;i<=m;i++)cout << a[i] << ' ' ;
cout << '\n';
return;
}
t = a[1] + a[m];
for(int l=1,r=m;l<r;i++){
if(a[l] + a[r] != t){
vector<int> v;
for(i=1;i<=m;i++){
if(i==l)continue;
v.pb(a[i]);
if(check(v)){
for(auto x : v)cout << x << ' ' ;
cout << '\n';
}
}
v.clear();
for(i=1;i<=m;i++){
if(i==r)continue;
v.pb(a[i]);
if(check(v)){
for(auto x : v)cout << x << ' ' ;
cout << '\n';
}
}
assert(false);
}
}
}
return;
}
/*
4 1
2 4 8 6 10
*/
signed main(){
FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
int _T;
cin >> _T;
for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
tabletennis.cpp: In function 'void solve(long long int)':
tabletennis.cpp:26:9: warning: unused variable 'j' [-Wunused-variable]
26 | int i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
492 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
2944 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |