Submission #385729

#TimeUsernameProblemLanguageResultExecution timeMemory
385729Osama_AlkhodairyTable Tennis (info1cup20_tabletennis)C++17
100 / 100
93 ms3564 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n, k; vector <int> a; bool check(int s){ int l = 0, r = n - 1; int cnt = (n - k) / 2; while(l < r){ if((r - l + 1) / 2 < cnt) return 0; if(a[l] + a[r] > s) r--; else if(a[l] + a[r] < s) l++; else{ cnt--; l++; r--; } } return cnt <= 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; n += k; a.resize(n); for(auto &i : a) cin >> i; vector <int> all; for(int i = 0 ; i <= k ; i++){ for(int j = n + i - k - 1 ; j < n ; j++){ all.push_back(a[i] + a[j]); } } sort(all.begin(), all.end()); all.resize(unique(all.begin(), all.end()) - all.begin()); int s = -1; for(auto &i : all){ if(check(i)){ s = i; break; } } assert(s > 0); vector <int> ans; int l = 0, r = n - 1; while(l <= r){ if(a[l] + a[r] > s) r--; else if(a[l] + a[r] < s) l++; else{ ans.push_back(a[l]); ans.push_back(a[r]); l++; r--; } } sort(ans.begin(), ans.end()); for(auto &i : ans) cout << i << " "; cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...