Submission #677235

#TimeUsernameProblemLanguageResultExecution timeMemory
677235LucaLucaMTable Tennis (info1cup20_tabletennis)C++17
100 / 100
181 ms4652 KiB
#include <bits/stdc++.h> using namespace std; /** trebuie sa alegem n din n + k numere astfel incat a[1] + a[n] = a[2] + a[n-1] = ... = a[n/2] + a[n/2+1] a[1] + a[n] = a[2] + a[n-1] a[n] - a[n-1] = a[2] - a[1] a[n-1] - a[n-2] = a[3] - a[2] ... a[n/2+1] - a[n/2] = a[n] - a[n-1] n*k + nlogn? **/ int a[150401]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; int m = n + k; for (int i=1; i<=m; i++) cin >> a[i]; sort(a+1, a+m+1); for (int i=1; i<=k+1; i++) /// O(k) { /// incercam sa fie a[i] cel mai mic element , a[j] cel mai mare for (int j=m; m-j+i-1 <= k; j--) /// O(k*k) { int sum = a[i] + a[j]; int l=i, r=j; int cnt = 0; while (l < r) { while (l < r && a[l] + a[r] > sum) r--; while (l < r && a[l] + a[r] < sum) l++; if (a[l] + a[r] != sum) { cnt = -1; break; } cnt++; l++; } if (cnt >= n/2) { cnt = n / 2; vector<int>ans; int l=i, r=j; while (l < r && cnt--) { while (l < r && a[l] + a[r] > sum) r--; while (l < r && a[l] + a[r] < sum) l++; ans.push_back(a[l]); ans.push_back(a[r]); l++, r--; } sort(ans.begin(), ans.end()); for (int x : ans) cout << x << ' '; return 0; } } } return 0; }
#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...