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>
using namespace std;
int a[300000], ans[300000], anssize, n, k;
void check(int sum)
{
anssize = 0;
int p = 0, l = 0, r = n + k - 1;
while (l < r)
{
if (a[l] + a[r] > sum) p++, r--;
else if (a[l] + a[r] < sum) p++, l++;
else
{
if (anssize < n)
ans[anssize++] = a[l], ans[anssize++] = a[r];
l++, r--;
}
if (p > k) return;
}
sort(ans, ans + anssize);
l = 0, r = anssize - 1;
while (l <= r)
{
cout << ans[l++] << ' ';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
for (int i = 0; i < n + k; i++)
{
cin >> a[i];
}
sort(a, a + n + k);
for (int i = 0; i <= k; i++)
{
for (int j = max(i + 1, n - 1); j < n + k; j++)
{
check(a[i] + a[j]);
}
}
return 0;
}
Compilation message (stderr)
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:36:24: warning: 'n' is used uninitialized in this function [-Wuninitialized]
36 | for (int i = 0; i < n + k; i++)
| ~~^~~
tabletennis.cpp:36:24: warning: 'k' is used uninitialized in this function [-Wuninitialized]
# | 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... |