This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
mt19937 rnd(time(0));
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,k;cin>>n>>k;
vector<int> v(n+k);
for(int i=0;i<n+k;i++){
cin>>v[i];
}
int flag=0;
unordered_set<int> s;
auto check=[&](int p)->void {
if(s.count(p)){
return;
}
s.insert(p);
int j=n+k-1;
int cnt=0;
vector<int> ans;
int no=0;
for(int i=0;i<n+k;i++){
while(i<j&&v[i]+v[j]>p){
no++;
j--;
}
if(i>=j){
break;
}
if(i<j&&v[i]+v[j]==p){
ans.push_back(v[i]);
ans.push_back(v[j]);
cnt+=2;
j--;
}
else{
no++;
}
if(no>k){
return;
}
}
//cout<<ans.size()<<endl;
if(cnt>=n){
sort(ans.begin(),ans.begin()+n);
for(int i=0;i<n;i++){
cout<<ans[i]<<' ';
}
cout<<endl;
flag=1;
}
};
while(!flag){
int i=rnd()%(k+1);
int j=n-1+rnd()%(k+1);
check(v[i]+v[j]);
}
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... |