이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |