#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define tern(cond, a, b) (cond ? a : b)
typedef long long lint;
typedef pair<int,int> ii;
int n, K;
vector<int> arr;
vector<int> dis;
vector<ii> stuff;
vector<int> X;
const int H = (1<<25)-1;
int cnt[H+1];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> K;
n += K;
arr.resize(n);
for(int i = 0;i < n;i++) cin >> arr[i];
for(int s = 0;s <= K+1;s++){
for(int e = n-1;e >= n-K-1;e--){
if(s + (n-1)-e > K) continue;
int str = arr[s]+arr[e];
dis.push_back(str);
}
}
sort(all(dis));
dis.erase(unique(all(dis)), dis.end());
for(register int i = K+1;i <= n-K-1;i++){
int other = n-i;
for(register int j = max(other-K-5,0);j <= min(n-1, other+K+5);j++){
if(i != j){
int S = arr[i]+arr[j];
cnt[S&H]++;
}
}
}
for(int s = 0;s <= K+1;s++){
for(int e = n-1;e >= n-K-1;e--){
if(s + (n-1)-e > K) continue;
int str = arr[s]+arr[e];
deque<int> ans;
for(int i = s;i < K+1;i++){
auto it = lower_bound(all(arr), str-arr[i]);
if(it == arr.end()) continue;
if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
}
for(int i = n-K;i <= e;i++){
auto it = lower_bound(all(arr), str-arr[i]);
if(it == arr.end()) continue;
if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
}
//auto it = lower_bound(all(stuff), ii(str, -1));
//int val = 0;
//if(it != stuff.end() and it->first == str) val = it->second;
if(sz(ans) + cnt[str&H] >= n-K){
ans.clear();
for(int i = s;i <= e;i++){
auto it = lower_bound(all(arr), str-arr[i]);
if(it == arr.end()) continue;
if(*it == str-arr[i] and arr[i] != str-arr[i]) ans.push_back(arr[i]);
}
while(sz(ans) > n-K){
ans.pop_front();
ans.pop_back();
}
for(int x : ans) cout << x << " ";
return 0;
}
}
}
}
Compilation message
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:40:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
40 | for(register int i = K+1;i <= n-K-1;i++){
| ^
tabletennis.cpp:42:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
42 | for(register int j = max(other-K-5,0);j <= min(n-1, other+K+5);j++){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
716 KB |
Output is correct |
2 |
Correct |
62 ms |
3352 KB |
Output is correct |
3 |
Correct |
50 ms |
3276 KB |
Output is correct |
4 |
Correct |
53 ms |
3344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
3344 KB |
Output is correct |
2 |
Correct |
52 ms |
3452 KB |
Output is correct |
3 |
Correct |
51 ms |
3264 KB |
Output is correct |
4 |
Correct |
53 ms |
3436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
11 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
11 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 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 |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
724 KB |
Output is correct |
3 |
Correct |
2 ms |
2380 KB |
Output is correct |
4 |
Correct |
2 ms |
1996 KB |
Output is correct |
5 |
Correct |
2 ms |
1996 KB |
Output is correct |
6 |
Correct |
2 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
76 ms |
4052 KB |
Output is correct |
3 |
Correct |
76 ms |
5380 KB |
Output is correct |
4 |
Correct |
72 ms |
4728 KB |
Output is correct |
5 |
Correct |
73 ms |
4768 KB |
Output is correct |
6 |
Correct |
72 ms |
3156 KB |
Output is correct |
7 |
Correct |
73 ms |
4328 KB |
Output is correct |
8 |
Correct |
79 ms |
4556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1024 KB |
Output is correct |
2 |
Correct |
2878 ms |
15384 KB |
Output is correct |
3 |
Correct |
1361 ms |
125664 KB |
Output is correct |
4 |
Correct |
2605 ms |
65160 KB |
Output is correct |
5 |
Correct |
597 ms |
50200 KB |
Output is correct |
6 |
Correct |
579 ms |
5440 KB |
Output is correct |
7 |
Correct |
2214 ms |
26284 KB |
Output is correct |
8 |
Correct |
1077 ms |
74176 KB |
Output is correct |