# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
632108 | boris_mihov | Table Tennis (info1cup20_tabletennis) | C++17 | 76 ms | 4720 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 <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <queue>
typedef long long llong;
const int MAXN = 150000 + 400 + 10;
const int INF = 1e9;
std::vector <int> solution;
int a[MAXN];
int n, k;
bool trySolution(int lp, int rp)
{
solution.clear();
int searchSum = a[lp] + a[rp];
solution.push_back(a[lp]);
solution.push_back(a[rp]);
lp++;
rp--;
while (lp <= rp-1 && solution.size() <= n-1)
{
if (rp - lp + 1 + solution.size() <= n-1) return false;
if (a[lp] + a[rp] == searchSum)
{
solution.push_back(a[lp]);
solution.push_back(a[rp]);
lp++;
rp--;
continue;
}
if (a[lp] + a[rp] < searchSum)
{
lp++;
continue;
}
if (a[lp] + a[rp] > searchSum)
{
rp--;
continue;
}
}
return solution.size() == n;
}
void solve()
{
std::sort(a + 1, a + 1 + n);
for (int i = 1 ; i <= k + 1 ; ++i)
{
for (int j = n + k ; j >= n + i - 1 ; --j)
{
if (trySolution(i, j))
{
std::sort(solution.begin(), solution.end());
for (const int &i : solution) std::cout << i << ' ';
std::cout << '\n';
return;
}
}
}
}
void read()
{
std::cin >> n >> k;
for (int i = 1 ; i <= n + k ; ++i)
{
std::cin >> a[i];
}
}
void fastIO()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIO();
read();
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... |