# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499893 | jesus_coconut | Table Tennis (info1cup20_tabletennis) | C++17 | 3066 ms | 79712 KiB |
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 pb push_back
#define all(a) begin(a), end(a)
using namespace std;
int n, k;
vector<int> v;
void load() {
cin >> n >> k;
v.resize(n + k);
for (auto &it : v) cin >> it;
}
vector<int> ans;
bool solve(int suma) {
ans.clear();
int l = 0, r = n + k - 1;
int cnt = 0;
while (l < r) {
if (v[l] + v[r] == suma) {
ans.pb(v[l]);
ans.pb(v[r]);
if (size(ans) == n) return true;
++l;
--r;
} else if (v[l] + v[r] < suma) {
++l;
if (++cnt < k) return false;
} else {
--r;
if (++cnt > k) return false;
}
}
return false;
}
set<int> bio;
void solve() {
while (true) {
int i = rand() % (n + k);
int j = n - 1 - i + (rand() % (2 * k + 1));
if (j < 0 || i == j || j >= n + k || bio.count(v[i] + v[j])) continue;
bio.insert(v[i] + v[j]);
if (solve(v[i] + v[j])) {
sort(all(ans));
for (auto &it: ans) cout << it << ' ';
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
load();
sort(all(v));
solve();
return 0;
}
Compilation message (stderr)
# | 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... |