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