//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define ll long long
#define maxn 160005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
//#include <bits/extc++.h>
//using namespace __gnu_pbds;
//template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//find by order, order of key
int a[maxn];
vector<int> ans;
bool solve(int x, int tot, bool rec, int v) {
int ret = 0, ind = tot - 1;
for (int i = 0;i < tot;i++) {
while (ind >= 0 && a[i] + a[ind] > x) {
ind--;
}
if (ind < i) break;
if (ind != i && a[i] + a[ind] == x) {
ret++;
if (i < ind && rec) ans.push_back(a[i]), ans.push_back(a[ind]);
}
if (ret == v) {
return true;
}
}
return false;
}
int main() {
io
int n, k;
cin >> n >> k;
for (int i = 0;i < n + k;i++) cin >> a[i];
for (int i = 0;i <= k;i++) {
for (int j = n + k - 1;j >= n + i - 1;j--) {
if (i >= j) continue;
if (solve(a[i] + a[j], n + k, false, n / 2)) {
solve(a[i] + a[j], n + k, true, n / 2);
sort(ans.begin(), ans.end());
for (int x:ans) cout << x << " ";
cout << "\n";
return 0;
}
}
}
}
/*
4 3
1 2 3 4 8 10 20
4 2
1 2 3 4 5 6
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
740 KB |
Output is correct |
2 |
Correct |
40 ms |
3036 KB |
Output is correct |
3 |
Correct |
39 ms |
3008 KB |
Output is correct |
4 |
Correct |
40 ms |
2992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
3008 KB |
Output is correct |
2 |
Correct |
40 ms |
3008 KB |
Output is correct |
3 |
Correct |
41 ms |
3080 KB |
Output is correct |
4 |
Correct |
45 ms |
3068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
197 ms |
3024 KB |
Output is correct |
3 |
Correct |
46 ms |
3016 KB |
Output is correct |
4 |
Correct |
83 ms |
3032 KB |
Output is correct |
5 |
Correct |
42 ms |
3092 KB |
Output is correct |
6 |
Correct |
53 ms |
3008 KB |
Output is correct |
7 |
Correct |
88 ms |
3040 KB |
Output is correct |
8 |
Correct |
41 ms |
3032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
3079 ms |
820 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |