#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]);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
796 KB |
Output is correct |
2 |
Correct |
41 ms |
3176 KB |
Output is correct |
3 |
Correct |
40 ms |
3196 KB |
Output is correct |
4 |
Correct |
41 ms |
3176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
3176 KB |
Output is correct |
2 |
Correct |
41 ms |
3144 KB |
Output is correct |
3 |
Correct |
42 ms |
3176 KB |
Output is correct |
4 |
Correct |
41 ms |
3244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
43 ms |
3176 KB |
Output is correct |
3 |
Correct |
41 ms |
3176 KB |
Output is correct |
4 |
Correct |
42 ms |
3208 KB |
Output is correct |
5 |
Correct |
41 ms |
3196 KB |
Output is correct |
6 |
Correct |
41 ms |
3176 KB |
Output is correct |
7 |
Correct |
42 ms |
3168 KB |
Output is correct |
8 |
Correct |
42 ms |
3168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
68 ms |
3120 KB |
Output is correct |
3 |
Correct |
45 ms |
4584 KB |
Output is correct |
4 |
Correct |
62 ms |
4632 KB |
Output is correct |
5 |
Correct |
72 ms |
4520 KB |
Output is correct |
6 |
Correct |
43 ms |
4616 KB |
Output is correct |
7 |
Correct |
90 ms |
4584 KB |
Output is correct |
8 |
Correct |
42 ms |
4584 KB |
Output is correct |