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>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=2e5+5;
const int inf=1e9;
int n, k;
int a[mxn];
bool cnt[2 * inf + 1];
bool check(int tot) {
int pair = 0;
for(int i = 1; i <= n + k; i++) {
if(tot - a[i] >= 0 && cnt[tot - a[i]]) pair++;
}
return pair >= n;
}
void print(int tot) {
int pair = 0;
vector<int> v;
for(int i = 1; i <= n + k && pair < n; i++) {
if(tot - a[i] >= 0 && cnt[tot - a[i]]) {
pair += 2;
v.push_back(a[i]);
v.push_back(tot - a[i]);
}
}
sort(v.begin(), v.end());
for(int i : v) cout<<i<<" ";
cout<<endl;
}
int main() {
cin >> n >> k;
for(int i = 1; i <= n + k; i++) {
cin >> a[i];
cnt[a[i]] = 1;
}
for(int i = 1; i <= min(n + k, k + 2); i++) {
for(int j = n + k; j >= max(1, n - 3 + i); j--) {
if(check(a[i] + a[j])) {
print(a[i] + a[j]);
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... |