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;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n, k;
vector <int> a;
bool check(int s){
int l = 0, r = n - 1;
int cnt = (n - k) / 2;
while(l < r){
if((r - l + 1) / 2 < cnt) return 0;
if(a[l] + a[r] > s) r--;
else if(a[l] + a[r] < s) l++;
else{
cnt--;
l++; r--;
}
}
return cnt <= 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
n += k;
a.resize(n);
for(auto &i : a) cin >> i;
vector <int> all;
for(int i = 0 ; i <= k ; i++){
for(int j = n + i - k - 1 ; j < n ; j++){
all.push_back(a[i] + a[j]);
}
}
sort(all.begin(), all.end());
all.resize(unique(all.begin(), all.end()) - all.begin());
int s = -1;
for(auto &i : all){
if(check(i)){
s = i;
break;
}
}
assert(s > 0);
vector <int> ans;
int l = 0, r = n - 1;
while(l <= r){
if(a[l] + a[r] > s) r--;
else if(a[l] + a[r] < s) l++;
else{
ans.push_back(a[l]);
ans.push_back(a[r]);
l++; r--;
}
}
sort(ans.begin(), ans.end());
for(auto &i : ans) cout << i << " ";
cout << endl;
}
# | 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... |