# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1029266 | berr | Table Tennis (info1cup20_tabletennis) | C++17 | 516 ms | 5336 KiB |
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;
void f(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
// f();
srand(time(0));
int n, k; cin >>n >> k;
vector<int> a(n+k);
for(auto &i: a) cin >> i;
vector<int> vis(n+k);
int ans=0;
vector<int> gh;
auto check=[&](int val, int type){
int p=n+k-1;
int all=0;
for(int i=0; i<p&&i<n+k&&all<n/2; i++){
while(p>0&&a[i]+a[p]>val) p--;
if(i<p&&a[i]+a[p]==val){
all++;
if(type){
gh.push_back(a[i]);
gh.push_back(a[p]);
}
}
}
if(all==n/2) return 1;
return 0;
};
if(k<20){
for(int i=0; i<=20&&i<n+k&&ans==0; i++){
for(int j=0; j<=20&&j<n+k-1&&ans==0; j++){
if(check(a[i]+a[n+k-j-1], 0)){
ans=a[i]+a[n+k-j-1];
}
}
}
}
while(ans==0){
int val=rand()%(3*k);
if(vis[val]) continue;
int j=k+val;
vis[val]=1;
for(int l=0; l<=j; l++){
if( check(a[val]+a[n+k-l-1], 0)){
ans=a[val]+a[n+k-l-1];
}
}
}
check(ans, 1);
sort(gh.begin(), gh.end());
for(auto i: gh) cout<<i<<" ";
}
Compilation message (stderr)
# | 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... |