#include <bits/stdc++.h>
#define pb push_back
#define all(a) begin(a), end(a)
using namespace std;
int n, k;
vector<int> v;
void load() {
cin >> n >> k;
v.resize(n + k);
for (auto &it : v) cin >> it;
}
int const N = 150005;
int ans[N];
bool solve(int suma) {
int l = 0, r = n + k - 1;
int cnt = 0;
int p = 0;
while (l < r) {
if (v[l] + v[r] == suma) {
ans[p++] = v[l];
ans[p++] = v[r];
if (p == n) return true;
++l;
--r;
} else if (v[l] + v[r] < suma) {
++l;
if (++cnt < k) return false;
} else {
--r;
if (++cnt > k) return false;
}
}
return false;
}
set<int> bio;
void solve() {
while (true) {
int i = rand() % (n + k);
int j = n + k - 1 - i - (rand() % (2 * k + 1));
if (i >= j || j >= n + k || bio.count(v[i] + v[j])) continue;
bio.insert(v[i] + v[j]);
if (solve(v[i] + v[j])) {
sort(ans, ans + n);
for (int i = 0; i < n; ++i) {
cout << ans[i] << ' ';
}
return;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
load();
sort(all(v));
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Output is correct |
2 |
Execution timed out |
3077 ms |
1780 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
2856 KB |
Output is correct |
2 |
Correct |
32 ms |
2908 KB |
Output is correct |
3 |
Execution timed out |
3068 ms |
924 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3078 ms |
716 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
3059 ms |
332 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
3078 ms |
10016 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3075 ms |
79084 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |