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;
int arr[150405],arr2[150005],n,k;
bool fun(int idx,int x,int y,int sum){
if(idx==n/2 && arr[x]+arr[y]==sum){
arr2[idx-1]=arr[x];
arr2[n-idx]=arr[y];
return true;
}
if((x-idx+1+n-1-y-idx+1==k&&arr[x]+arr[y]!=sum)||y-1==x ||y==x){return false;}
if(arr[x]+arr[y]==sum){
if(fun(idx+1,x+1,y-1,sum)){
arr2[idx-1]=arr[x];
arr2[n-idx]=arr[y];
return true;
}
else{return false;}
}
if(arr[x]+arr[y]>sum){return fun(idx,x,y-1,sum);}
if(arr[x]+arr[y]<sum){return fun(idx,x+1,y,sum);}
}
int main() {
cin>>n>>k;
for(int i=0;i<n+k;i++){
cin>>arr[i];
}
for(int i=0;i<=k;i++){
for(int j=n+k-1;j>=i-1+n;j--){
if(fun(1,i,j,arr[i]+arr[j])){
cout<<arr2[0];
for(int g=1;g<n;g++){
cout<<" "<<arr2[g];
}
return 0;
}
}
}
return 0;
}
Compilation message (stderr)
tabletennis.cpp: In function 'bool fun(int, int, int, int)':
tabletennis.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
24 | }
| ^
# | 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... |