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;
const int N = 160003;
const int K = 403;
int n, k;
int a[N];
void solve(int lo, int hi, int sum)
{
vector < int > res;
int cur = 1;
res.push_back(a[lo]), res.push_back(a[hi]);
int i = lo + 1, j = hi - 1;
int dem = hi - lo + 1 - n ;
while (i < j && cur < n / 2 && dem >= 0)
{
if (a[i] + a[j] > sum) j--, dem--;
if (a[i] + a[j] < sum) i++, dem--;
if (a[i] + a[j] == sum)
{
cur++;
res.push_back(a[i]);
res.push_back(a[j]);
i++; j--;
}
if (cur == n / 2) break;
}
if (cur == n / 2)
{
sort(res.begin(), res.end());
for (int u : res)
cout << u << " ";
exit(0);
}
return;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
int m = n + k;
for (int i = 1; i <= m; i++)
cin >> a[i];
sort(a + 1, a + m + 1);
for (int i = 1; i <= k + 1; i++)
{
for (int j = i + n - 1; j <= m; j++)
{
solve(i, j, a[i] + a[j]);
}
}
}
# | 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... |