#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1.5e5+505;
int a[N],n,k;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=0;i<n+k;++i)
cin>>a[i];
//O(nk^2+k^3)
unordered_map<int,int>occ;
vector<int>v;
for(int fi=0;fi<k;++fi){
for(int se=fi+n-1;se<n+k;++se){
int x=a[fi]+a[se];
for(int i=fi+1;i<se;++i)
++occ[a[i]];
v.push_back(a[fi]);
v.push_back(a[se]);
for(int i=fi+1;i<se;++i){
if(2*a[i]>x)break;
if(2*a[i]==x){
if(occ[a[i]]<2)continue;
v.push_back(a[i]);
v.push_back(a[i]);
occ[a[i]]-=2;
}else if(occ[x-a[i]]){
v.push_back(a[i]);
v.push_back(x-a[i]);
--occ[x-a[i]];
--occ[a[i]];
}
}
if(v.size()>=n){
sort(v.begin(),v.end());
for(auto&x:v)
cout<<x<<' ';
return 0;
}
occ.clear();
v.clear();
}
}
assert(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... |