제출 #1318325

#제출 시각아이디문제언어결과실행 시간메모리
1318325husu1331Table Tennis (info1cup20_tabletennis)C++20
100 / 100
555 ms15748 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 ; int k ; cin >> k ; n += k ; vector<int>a(n) ; map<int , int>mp ; map<int , int>pos ; for(int i = 0 ; i < n ; i ++) { cin >> a[i] ; mp[a[i]] ++ ; } if(nc == 3 and k == 1) { cout << a[0] << ' ' << a[1] ; return ; } sort(a.begin() , a.end()) ; if(k == 1) { int nn = a.size() ; vector<bool>check(nn) ; int l = 1 ; int r = nn - 1; map<int , int>rep ; while(l <= r) { int sum = a[l] + a[r] ; l ++ ; r -- ; rep[sum] ++ ; } l = 0 ; r = nn - 2 ; while(l <= r) { int sum = a[l] + a[r] ; l ++ ; r -- ; rep[sum] ++ ; } int sum = 0 ; int maks = -1 ; for(auto i : rep) { if(maks < i.ss) { maks = i.ss ; sum = i.ff ; } } int pos = -1 ; for(int i = 0 ; i < n ; i ++) { if(check[i] == 0) { check[i] = 1 ; int dif = sum - a[i] ; if(mp[dif] == 0) { pos = i ; break ; } } } for(int i = 0 ; i < n ; i ++) { if(i != pos) { cout << a[i] << ' ' ; } } } else { for(int i = 0 ; i <= k ; i ++) { for(int j = 0 ; j <= k ; j ++) { if(i < n - 1 - j){ int sum = a[i] + a[n - 1 - j] ; int l = 0 ; int r = n - 1 ; int cnt = 0 ; int g = -1 ; vector<int>ans ; while(l < r) { if(cnt > k) { break ; } int summ = a[l] + a[r] ; if(summ == sum) { ans.push_back(a[l]) ; ans.push_back(a[r]) ; l ++ ; r -- ; } else { cnt ++ ; if(summ > sum) { r -- ; } else { l ++ ; } } } if(ans.size() == nc) { sort(ans.begin() , ans.end()) ; for(int i = 0 ; i < nc ; i ++) { cout << ans[i] << ' ' ; } 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...