// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#ifdef ULVI
#include "debug.hpp"
#else
#define db(...)
#define dbv(v)
#define line()
#endif
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define enld endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll sz=2e5+100;
const ll lg=20;
const ll mod=1e9+7;
const ll inf=1e18;
template<class T>
using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
ll n,k;
cin>>n>>k;
vector<ll> v(n+k);
for(ll i=0;i<n+k;i++) cin>>v[i];
for(ll i=0;i<=k;i++){
for(ll j=0;i+j<=k;j++){
ll l=i,r=n+k-j-1;
vector<ll> ans={v[l],v[r]};
ll sum=v[l]+v[r];
l++; r--;
ll rem=k-i-j;
while(l<=r && rem>=0){
if(l==r){
rem--;
break;
}
if(v[l]+v[r]==sum){
ans.push_back(v[l]);
ans.push_back(v[r]);
l++; r--;
}
else if(v[l]+v[r]<sum){
l++;
rem--;
}
else{
r--;
rem--;
}
}
if(rem<0) continue;
while(ans.size()>n){
ans.pop_back();
ans.pop_back();
}
sort(all(ans));
for(ll i:ans) cout<<i<<' ';
return;
}
}
}
int main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t=1;
// cin>>t;
for(ll _=1;_<=t;_++){
// cout<<"Scenario #"<<_<<":\n";
solve();
}
}
| # | 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... |