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 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 (stderr)
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 |
---|
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... |