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;
int a[150100];
int n,k;
bool check(int x){
int l = 1;
int r = n;
int cnt = 0;
while (l < r){
if (a[l] + a[r] > x){cnt++;r--;}
else if (a[l] + a[r] < x){l++;cnt++;}
else{l++;r--;}
if (cnt > k)return 0;
}
return 1;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>k;n += k;
for (int i = 1;i <= n;i ++){
cin>>a[i];
}
sort(a+1,a+1+n);
vector <int> all;
for (int i = 0;i <= k;i ++){
for (int j = 0;j <= i;j ++){
int l = j + 1;
int r = n - (i - j);
all.push_back(a[l] + a[r]);
}
}
sort(all.begin(),all.end());
all.resize(unique(all.begin(),all.end())-all.begin());
for (auto x:all){
if (check(x)){
int l = 1;
int r = n;
vector <int> ans;
while (l < r){
if (a[l] + a[r] > x){r--;}
else if (a[l] + a[r] < x){l++;}
else {ans.push_back(a[l]);ans.push_back(a[r]);l++;r--;}
}
sort(ans.begin(),ans.end());
for (auto y:ans)cout<<y<<' ';
cout<<'\n';
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... |