#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;
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];
auto it = lower_bound(all(dis), S);
if(it == dis.end()) break;
if(*it == S) X.push_back(arr[i]+arr[j]);
}
}
}
if(n > 2000 and K > 20) return 0;
sort(all(X));
for(int x : X){
if(stuff.empty() or stuff.back().first != x) stuff.push_back(ii(x,1));
else stuff.back().second++;
}
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) + val >= 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:37:19: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
37 | for(register int i = K+1;i <= n-K-1;i++){
| ^
tabletennis.cpp:39:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
39 | for(register int j = max(other-K-5,0);j <= min(n-1, other+K+5);j++){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1096 KB |
Output is correct |
2 |
Correct |
56 ms |
4680 KB |
Output is correct |
3 |
Correct |
59 ms |
4528 KB |
Output is correct |
4 |
Correct |
63 ms |
4080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
4592 KB |
Output is correct |
2 |
Correct |
65 ms |
4660 KB |
Output is correct |
3 |
Correct |
61 ms |
4068 KB |
Output is correct |
4 |
Correct |
80 ms |
4104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
11 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
8 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
224 ms |
4680 KB |
Output is correct |
3 |
Correct |
126 ms |
4636 KB |
Output is correct |
4 |
Correct |
161 ms |
5244 KB |
Output is correct |
5 |
Correct |
144 ms |
4728 KB |
Output is correct |
6 |
Correct |
324 ms |
34880 KB |
Output is correct |
7 |
Correct |
153 ms |
5400 KB |
Output is correct |
8 |
Correct |
144 ms |
5676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
976 KB |
Output is correct |
2 |
Execution timed out |
3072 ms |
9600 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |