Submission #1318992

#TimeUsernameProblemLanguageResultExecution timeMemory
1318992husuuuTable Tennis (info1cup20_tabletennis)C++20
63 / 100
271 ms3184 KiB
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////////
//#define int long long
#define endl "\n"
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define INF 0x3F3F3F3F3F3F3F3F
#define ss second
#define ff first
#define pb push_back
#define ins insert
#define fori for(int i = 0 ; i < n ; i ++)
///////////////////////////////////////////////
const int sz = 2e3 + 5 ;
const int LG = 20 ;
const int N = 1e3 ;
const int mod = 1e9 + 7 ;
const int MAXM = 1e5 ;
///////////////////////////////////////////////
///////////////////////////////////////////////
void solve() {
  int n ;
  cin >> n ;
  int nc = n ; // Orijinal N (nece nefer secmeliyik)
  int k ;
  cin >> k ;
  n += k ; // Umumi say
  vector<int>a(n) ;
  
  // Map-leri sildim, cunki cox yavashdir ve ehtiyac yoxdur
  for(int i = 0 ; i < n ; i ++) {
    cin >> a[i] ;
  }
  
  if(nc == 2 and k == 1) {
    cout << a[0] << ' ' << a[1] ;
    return ;
  }
  
  sort(a.begin() , a.end()) ;
  
  // nn evezine n istifade edirik (artiq n = N+K)
  for(int i = 0 ; i <= k ; i ++) {
    // Sizin mentiq: soldan i, sagdan (k-i) element buraxiriq
    int l_idx = i ;
    int r_idx = n - (k - i) - 1 ; 
    
    if (l_idx >= r_idx) continue; // Guvenlik ucun

    int sum = a[l_idx] + a[r_idx] ;
    
    // Two Pointers ile bu cemi veren nece cutluk oldugunu sayaq
    int cnt = 0;
    int l = 0, r = n - 1;
    while(l < r) {
      int cur = a[l] + a[r];
      if(cur == sum) {
        cnt++;
        l++;
        r--;
      }
      else if(cur < sum) l++;
      else r--;
    }

    // Bug duzelishi: Bizə nc/2 qeder cütlük lazımdır, nn/2 yox
    if(cnt >= nc / 2) {
      vector<int> ans;
      l = 0; 
      r = n - 1;
      int pairs_needed = nc / 2;
      
      // Cavabi yigmaq ucun yeniden Two Pointers
      while(l < r && pairs_needed > 0) {
        int cur = a[l] + a[r];
        if(cur == sum) {
          ans.push_back(a[l]);
          ans.push_back(a[r]);
          pairs_needed--;
          l++;
          r--;
        }
        else if(cur < sum) l++;
        else r--;
      }
      
      // Cavabi artan sira ile cixarmaq lazimdir
      sort(ans.begin(), ans.end());
      
      for(int j = 0 ; j < ans.size() ; j ++) cout << ans[j] << ' ' ;
      return ;
    }
  }
}
///////////////////////////////////////////////
///////////////////////////////////////////////
signed main() {
  IO ;
  int t = 1 ; // cin >> t ;
  while(t --) {
    solve() ;
    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...