Submission #525449

#TimeUsernameProblemLanguageResultExecution timeMemory
525449scwadrTable Tennis (info1cup20_tabletennis)C++17
100 / 100
124 ms4452 KiB
#include <iostream> #include <algorithm> using namespace std; int a[300000], ans[300000], anssize, n, k; bool check(int sum) { anssize = 0; int p = 0, l = 0, r = n + k - 1; while (l < r) { if (a[l] + a[r] > sum) p++, r--; else if (a[l] + a[r] < sum) p++, l++; else { if (anssize < n) ans[anssize] = a[l], ans[anssize+1] = a[r]; anssize+=2; l++, r--; } if (p > k) return false; } sort(ans, ans + anssize); l = 0, r = anssize - 1; while (l <= r) { cout << ans[l++] << ' '; } return true; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int i = 0; i < n + k; i++) { cin >> a[i]; } sort(a, a + n + k); bool ok = false; for (int i = 0; i <= k && !ok; i++) { for (int j = max(i + 1, n - 1); j < n + k && !ok; j++) { if (check(a[i] + a[j])) ok = true; } } 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...