This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define ceil(x) NEVER USE CEIL
#define sqrt(x) (int)(sqrt(x))
const int MAX=1e7;
const int MOD=1e9+7;
const int MAAX=1e18;
vector<int>v;
int arr[150410],n,k;
bool fun(int l,int r,int x,int sum){
int s=l,e=r;
v.clear();
while((e-s+1)>sum){
if(arr[s]+arr[e]==x){
v.pb(arr[s]);
v.pb(arr[e]);
s++,e--;
}
else if(arr[s]+arr[e]>x&&sum>0){
e--,sum--;
}
else if(sum>0){
s++,sum--;
}
else
return 0;
}
return 1;
}
in main()
{
iostream::sync_with_stdio(0);
int tc=1;
//cin>>tc;
while(tc--){
cin>>n>>k;
for(int i=0;i<n+k;i++)
cin>>arr[i];
for(int i=0;i<n+k;i++){
for(int l=n+k-1;l>=n-1+i;l--){
if(fun(i+1,l-1,arr[i]+arr[l],k-((n+k-1)-l+i))){
v.pb(arr[i]);
v.pb(arr[l]);
sort(v.begin(),v.end());
for(int i=0;i<n;i++)
cout<<v[i]<<" ";
return 0;
}
}
}
}
return 0;
}
# | 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... |