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 n, k, m, arr[200405];
void check(int sum){
vector<int> res;
for(int l = 0, r = m-1; l<r;){
if(arr[l]+arr[r]==sum) res.push_back(arr[l]), res.push_back(arr[r]), ++l, --r;
else if(arr[l]+arr[r]<sum) ++l;
else --r;
}
while((int)res.size()>n) res.pop_back();
if((int)res.size()<n) return;
sort(res.begin(), res.end());
for(auto x : res)
cout << x << ' ';
cout << '\n'; exit(0);
}
int main(){
// freopen("a.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k; m = n+k;
for(int i = 0; i<m; ++i)
cin >> arr[i];
sort(arr, arr+m);
vector<int> todo;
if(m<4*k){
for(int i = 0; i<m; ++i)
for(int j = i+1; j<m; ++j)
todo.push_back(arr[i]+arr[j]);
sort(todo.begin(), todo.end());
todo.erase(unique(todo.begin(), todo.end()), todo.end());
} else{
map<int, int> cnt;
for(int i = 0; i<2*k; ++i)
for(int j = 0; j<2*k; ++j)
cnt[arr[i]+arr[m-1-j]]++;
for(auto [x, y] : cnt)
if(y>=k) todo.push_back(x);
}
for(auto x : todo)
check(x);
}
# | 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... |