Submission #1317962

#TimeUsernameProblemLanguageResultExecution timeMemory
1317962ayazTable Tennis (info1cup20_tabletennis)C++20
49 / 100
23 ms5816 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define all(x) (x).begin(), (x).end()
#define isz(x) (int)(x.size())
#define int ll

const int sz = 500200, inf = 1000000000;

void run_case(int tc) {
  int n, k; cin >> n >> k;
  vector<int> a(n + k + 1);
  for (int i = 1; i <= n + k; i++) {
    cin >> a[i];
  }
  for (int l = 0; l <= k; l++) {
    for (int r = 0; r <= k; r++) {
      if (l + r > k) continue;
      // 4
      // 1 2 3 4 5 6 7 8 9 10
      int mn = a[l + 1], mx = a[n + k - r]; 
      vector<pair<int, int>> v;
      int L = l + 1, R = n + k - r;
      while (L <= R && isz(v) < n / 2) {
        int target = mx + mn - a[L];
        while (a[R] > target) R--;
        if (a[R] == target) { 
          v.push_back({L, R});
          L++;
          R--;
        } else break;
      }
      if (isz(v) == n / 2) {
        vector<int> ans;
        for (auto [x, y] : v) {
          ans.push_back(x);
          ans.push_back(y);
        }
        sort(all(ans));
        for (auto i : ans) {
          cout << a[i] << ' ';
        }
        return;
      }
    }
  }
}
void precompute() {}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#ifdef LOCAL
  // freopen("err.log", "w", stderr);
#endif
  precompute();
  int t = 1; // cin >> t;
  for (int tc = 1; tc <= t; tc++) run_case(tc);
}
#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...