#include <bits/stdc++.h>
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 150000;
const int MAXK = 400;
const int B = 1000;
int N, K;
int a[MAXN+MAXK+1];
bool flag[MAXN+MAXK+1];
unordered_map <int,int> arr;
bool check(int S) {
int nowR = N+K, cnt = 0;
for (int i = 1; i <= N+K; i++) flag[i] = false;
for (int i = 1; i < nowR; i++) {
while (a[i] + a[nowR] > S && nowR > i)
nowR--;
if (nowR > i && a[i] + a[nowR] == S) {
flag[i] = flag[nowR] = true;
cnt++;
nowR--;
}
if (cnt == N / 2) break;
}
return cnt == N / 2;
}
void solve() {
for (int i = 1; i <= B+1; i++) {
for (int j = N+K-B; j <= N+K; j++) {
if (i < j) arr[a[i] + a[j]]++;
}
}
for (auto [v, c] : arr) {
if (c >= 800 && check(v)) {
return;
}
}
}
void naive() {
for (int L = 1; L <= K+1; L++) {
for (int R = N; R <= N+K; R++) {
if (R-L+1 < N) continue;
fill(flag+1, flag+1+N+K, false);
int S = a[L] + a[R], cnt = 1;
flag[L] = flag[R] = true;
int nowR = R-1;
for (int i = L+1; i < nowR; i++) {
while (a[i] + a[nowR] > S && nowR > i)
nowR--;
if (a[i] + a[nowR] == S) {
flag[i] = flag[nowR] = true;
cnt++;
nowR--;
}
}
if (cnt == N / 2) return;
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
for (int i = 1; i <= N+K; i++) {
cin >> a[i];
}
if (N+K <= B) {
naive();
} else {
assert(false);
solve();
}
for (int i = 1; i <= N+K; i++) {
if (flag[i]) cout << a[i] << ' ';
}
cout << '\n';
return 0;
}
Compilation message
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:38:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
38 | for (auto [v, c] : arr) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
588 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
1648 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 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 |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Runtime error |
23 ms |
1668 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
20 ms |
1616 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |