This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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++){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |