#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 && cnt <= k) {
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;
++cnt;
} else {
--r;
++cnt;
}
}
return false;
}
map<int, int> mp;
void solve() {
vector<int> tmp;
for (int at = 1; ; ++at) {
for (int t = 0; t < 100 * k; ++t) {
int i = rand() % (n + k);
int j = n + k - 1 - i - (rand() % (2 * k + 1));
if (i >= j || j >= n + k) continue;
if (mp[v[i]+v[j]]++ == 0) {
tmp.pb(v[i] + v[j]);
};
}
sort(all(tmp), [&](int const &a, int const &b) { return mp[a] > mp[b]; });
for (auto a: tmp) {
if (solve(a)) {
sort(ans, ans + n);
for (int i = 0; i < n; ++i) {
cout << ans[i] << ' ';
}
return;
}
}
tmp.clear();
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
load();
sort(all(v));
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3061 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
588 KB |
Output is correct |
2 |
Execution timed out |
3070 ms |
1684 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2884 KB |
Output is correct |
2 |
Correct |
47 ms |
2976 KB |
Output is correct |
3 |
Execution timed out |
3075 ms |
976 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3067 ms |
744 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
3074 ms |
352 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
3070 ms |
9980 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
460 KB |
Output is correct |
2 |
Execution timed out |
3072 ms |
30916 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |