#include "bits/stdc++.h"
#define int long long
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
using namespace std;
void _(){
int n,k;
cin >> n >> k;
int M = n + k;
int ar[M+5];
for(int i=1;i<=M;i++) cin >> ar[i];
for(int l=1;l<=k+1;l++){
for(int r=M;r>=M-k;r--){
if(l-1+M-r>k || r-l+1 < n) continue;
int p = r, val = ar[l] + ar[r];
vector<int> ans;
for(int i = l; i <= r ; i++){
if(sz(ans) == n || p-i+sz(ans)+1 < n) break;
if(ar[i] > val / 2) continue;
while(p > i && ar[i] + ar[p] > val) p--;
if(p <= i) break;
if(ar[i] + ar[p] == val && sz(ans) < n){
ans.push_back(ar[i]);
ans.push_back(ar[p]);
}
}
if(sz(ans) == n){
sort(all(ans));
for(int x:ans) cout << x << ' ';
cout << '\n';
return;
}
}
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
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... |