#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define prl pair<ll, ll>
#define pll array<ll, 2>
#define lll array<ll, 3>
#define ss second
#define ff first
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
#define endl '\n'
#define oset tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const ll N = 1e5 + 5;
const ll inf = 1e17;
void _(){
ll n, k; cin >> n >> k;
set<ll>cand; ll og = n; n += k;
vector<ll>a(n); for(ll &i : a) cin >> i;
for(ll i = 0; i <= k; i++){
for(ll j = n - k + i - 1; j < n; j++){
ll s = a[i] + a[j], l = 0, r = n - 1 ,rem = 0;
deque<ll>lf, rg;
while(l <= r and rem <= k){
ll sm = a[l] + a[r];
if(sm > s) r--, rem++;
if(sm < s) l++, rem++;
if(sm == s){
lf.push_back(a[l++]);
rg.push_front(a[r--]);
}
}
if(rem == k){
for(ll &i : lf) cout << i << ' ';
for(ll &i : rg) cout << i << ' ';
cout << '\n'; break;
}
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(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... |