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;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
fastIO;
//freopen("in.txt","r",stdin);
int n, k;
cin >> n >> k;
int m = (n + k);
vector<int> q(m);
for(int i = 0; i < m ; i ++)
cin >> q[i];
sort(q.begin(), q.end());
vector<pii> tak;
for(int i = 0 ; i < m ; i ++ ){
for(int j = 1; j <= k + 1; j ++ ){
if(i + j < m && i + 1 >= n/2 && m-(i+j) >= n/2){
tak.push_back(mp(i,i+j));
}
}
}
random_shuffle(tak.begin(), tak.end());
int pari = 0;
int rem = n/2;
vector<int> soln;
int ci, cj;
int pi, pj;
bool brok;
for(auto pari : tak){
rem = n/2-1;
pi = pari.fi;
pj = pari.se;
soln.clear();
soln.push_back(pi);
soln.push_back(pj);
ci = pi-1;
cj = pj+1;
while(rem > 0){
if(ci < 0 || cj >= m || (ci + 1) < rem || (m-cj) < rem) break;
if(q[pi]+q[pj] == q[ci]+q[cj]){
soln.push_back(ci);
soln.push_back(cj);
pi = ci;
pj = cj;
ci -- ;
cj ++ ;
rem -- ;
}
else{
if(q[ci]+q[cj] > q[pi]+q[pj]){
ci--;
}
else{
cj++;
}
}
}
if(rem == 0){
sort(soln.begin(), soln.end());
for(auto x : soln)
cout << q[x] << " ";
cout << "\n";
return 0;
}
}
return 0;
}
Compilation message (stderr)
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:32:9: warning: unused variable 'pari' [-Wunused-variable]
32 | int pari = 0;
| ^~~~
tabletennis.cpp:37:10: warning: unused variable 'brok' [-Wunused-variable]
37 | bool brok;
| ^~~~
# | 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... |