이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;
template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }
mt19937 rng((uint64_t) new char);
int solve(){
int n, k;
cin >> n >> k;
int z = n + k;
vec <int> a(z);
for (auto &i: a) cin >> i;
set <int> s(all(a));
auto get_ans = [&](int x){
vec <int> ans;
for (int i = 0; i < z; ++i){
if (2 * a[i] != x && s.find(x - a[i]) != s.end() && n){
ans.push_back(a[i]);
ans.push_back(x - a[i]);
s.erase(a[i]), s.erase(x - a[i]), n -= 2;
}
}
sort(all(ans));
for (int i = 0; i < sz(ans); ++i){
cout << ans[i];
if (i + 1 != sz(ans)) cout << " ";
}
exit(0);
};
if (n <= k){
for (int i = 0; i < z; ++i){
for (int j = i + 1; j < z; ++j){
int x = a[i] + a[j];
int cnt = 0;
for (int l = 0; l < z; ++l){
cnt += 2 * a[l] != x && s.find(x - a[l]) != s.end();
}
if (cnt >= n) get_ans(x);
}
}
return 0;
}
shuffle(all(a), rng);
while(true){
int ai = a[rng() % z];
for (auto &aj: a){
int x = ai + aj;
int cnt = 0;
for (int i = 0; i < min(z, 3 * k); ++i){
cnt += 2 * a[i] != x && s.find(x - a[i]) != s.end();
}
if (cnt > 2 * k) get_ans(x);
}
}
return 0;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tst = 1; //cin >> tst;
while(tst--) solve();
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... |