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 ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
int n,k,m;
cin>>n>>k;
m=n+k;
int a[m];
for(int i=0;i<m;i++)cin>>a[i];
for(int i=0;i<k+1;i++){
int x=k-i;
for(int j=m-1;j>=i&&k-i-(m-1-j)>=0;j--){
int x=k-i-(m-1-j),s=a[i]+a[j],c=0;
int l=i,r=j;
vector<pii> v;
while(l<r){
if(a[l]+a[r]==s){
v.pb({a[l],a[r]});
l++;
r--;
c++;
}else if(a[l]+a[r]<s){
l++;
x--;
}else{
r--;
x--;
}
if(x<0)break;
if(c==n/2)break;
}
if(c==n/2){
for(pii p:v)cout<<p.fs<<' ';
reverse(v.begin(),v.end());
for(pii p:v)cout<<p.sc<<' ';
return;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
Compilation message (stderr)
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:18:13: warning: unused variable 'x' [-Wunused-variable]
18 | int x=k-i;
| ^
# | 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... |