#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define int long long
#define ll long long
#define repp(i,x,n) for(int i=x;i<=n;i++)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repo(i,x,n) for(int i=x;i>=n;i--)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define r0 return 0
#define fi first
#define se second
#define liow ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define jelek cout<<"jelek"<<endl
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pi pair<pair<int,int>,pair<int,int>>
#define p3 pair<int,pair<int,int>>
#define fl fflush(stdout)
#define lb long double
#define p4 pair<pair<int,int>,pair<int,int>>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag, tree_order_statistics_node_update>;
const int mod=1e9+7,maxn=2e5+5,N=4e5,INF=1e18,MOD=998244353,LOG=20;
mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
void solve(){
int n,k;cin>>n>>k;
int a[n+k+2];
repp(i,1,n+k) cin>>a[i];
repp(i,1,k){
repp(j,n,n+k){
if(i>=j) continue;
vector<int>ans;
int l=i,r=j;
int sum=a[l]+a[r];
int KONTOL=0;
while(l<=r){
if(a[l]+a[r]==sum){
ans.pb(a[l]);
ans.pb(a[r]);
l++,r--;
} else if(a[l]+a[r]<sum){
l++;
KONTOL++;
} else {
r--;
KONTOL++;
}
if(ans.size()==n || KONTOL>k){
break;
}
}
if(ans.size()==n){
sort(all(ans));
for(auto x:ans) cout<<x<<" ";
cout<<endl;
return;
}
}
}
}
signed main(){
liow;
int t=1;
// cin>>t;
while(t--) 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... |