# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
835008 | alex_2008 | Table Tennis (info1cup20_tabletennis) | C++14 | 518 ms | 5692 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 <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
const int N = 15e4 + 410;
int a[N];
signed main()
{
srand(time(0));
int n, k;
cin >> n >> k;
for (int i = 1; i <= n + k; i++) {
cin >> a[i];
}
sort(a + 1, a + n + k + 1);
if (n * k * k <= 240000000) {
for (int i = 1; i <= k + 1; i++) {
for (int j = n + k; j >= i + n - 1; j--) {
int sm = a[i] + a[j], cnt = 0;
int k1 = i, k2 = j;
while (k1 < k2) {
if (a[k1] + a[k2] == sm) {
cnt++;
k1++;
k2--;
}
else if (a[k1] + a[k2] > sm) {
k2--;
}
else k1++;
}
if (cnt >= (n / 2)) {
k1 = i; k2 = j;
vector <int> v;
while (k1 < k2) {
if (a[k1] + a[k2] == sm) {
if (v.size() != n) {
v.push_back(a[k1]);
v.push_back(a[k2]);
}
cnt++;
k1++;
k2--;
}
else if (a[k1] + a[k2] > sm) {
k2--;
}
else k1++;
}
sort(v.begin(), v.end());
for (auto it : v) {
cout << it << " ";
}
cout << "\n";
return 0;
}
}
}
}
else {
while (1) {
int i = rand() % (n / 2) + 1;
for (int j = min(n + k, n + 2 * k + 1 - i); j >= (n + 1 - i); j--) {
int sm = a[i] + a[j];
int k1 = 1, k2 = n + k, cnt = 0;
while (k1 < k2) {
if (a[k1] + a[k2] == sm) {
cnt++;
k1++;
k2--;
}
else if (a[k1] + a[k2] > sm) {
k2--;
}
else k1++;
}
if (cnt >= (n / 2)) {
k1 = 1; k2 = n + k;
vector <int> v;
while (k1 < k2) {
if (a[k1] + a[k2] == sm) {
if (v.size() != n) {
v.push_back(a[k1]);
v.push_back(a[k2]);
}
cnt++;
k1++;
k2--;
}
else if (a[k1] + a[k2] > sm) {
k2--;
}
else k1++;
}
sort(v.begin(), v.end());
for (auto it : v) {
cout << it << " ";
}
cout << "\n";
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... |