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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
const int N = 2e5+10;
const int K = 50;
int a[N], n, k, sz;
gp_hash_table<int, bool> m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
sz=n+k;
for (int i=1; i<=sz; ++i) cin>>a[i];
for (int i=1; i<=sz; ++i) m[a[i]]=true;
vector<int> x;
bool ok=false;
for (int i=1; i<=sz && !ok; ++i) {
for (int j=sz; j>=sz-k+i-1 && !ok; --j) {
int num=0, s=a[i]+a[j];
for (int k=1; k<=sz; ++k) {
if (2*a[k] == s || m.find(s-a[k]) == m.end()) continue;
++num;
}
if (num >= n) {
int p=0;
for (int k=1; k<=sz; ++k) {
if (2*a[k] == s || m.find(s-a[k]) == m.end()) continue;
x.push_back(a[k]), x.push_back(s-a[k]);
p+=2;
if (p == n) break;
}
ok=true;
break;
}
}
}
sort(x.begin(), x.end());
assert((int)x.size() == n);
for (auto u : x) cout<<u<<" ";
cout<<"\n";
}
# | 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... |