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