제출 #365754

#제출 시각아이디문제언어결과실행 시간메모리
365754tengiz05Table Tennis (info1cup20_tabletennis)C++17
58 / 100
3105 ms564828 KiB
#include <bits/stdc++.h> using namespace std; //~ #define int long long #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define PI acos(-1) #define ld long double template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;} template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;} const int mod = 1e9+7, N = 2e5+5; int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;} int n, m, k; int a[N]; bool check(vector<int> &v){ int n = v.size(); int t = v[0] + v[n-1]; for(int l=0,r=n-1;l<r;l++,r--){ if(v[l] + v[r] != t)return false; }return true; } void solve(int test_case){ int i, j; cin >> n >> k; m = n+k; for(i=1;i<=m;i++){ cin >> a[i]; } sort(a+1,a+m+1); if(k == 1){ bool ok = true; int t = (a[1] + a[m-1]); for(int l=1,r=m-1;l<r;l++,r--){ if(a[l] + a[r] != t)ok = false; } if(ok){ for(i=1;i<=m-1;i++)cout << a[i] << ' ' ; cout << '\n'; return; } ok = true; t = (a[2] + a[m]); for(int l=2,r=m;l<r;l++,r--){ if(a[l] + a[r] != t)ok = false; } if(ok){ for(i=2;i<=m;i++)cout << a[i] << ' ' ; cout << '\n'; return; } t = a[1] + a[m]; for(int l=2,r=m-1;l<r;l++,r--){ if(a[l] + a[r] != t){ vector<int> v; for(i=1;i<=m;i++){ if(i==l)continue; v.pb(a[i]); } if(check(v)){ for(auto x : v)cout << x << ' ' ; cout << '\n'; return; } v.clear(); for(i=1;i<=m;i++){ if(i==r)continue; v.pb(a[i]); } if(check(v)){ for(auto x : v)cout << x << ' ' ; cout << '\n'; return; } assert(false); } } }else { map<int,int> possible_sums_not; for(i=1;i<=m;i++){ for(j=i+1;j<m;j++){ possible_sums_not[a[i] + a[j]]++; } } vector<pii> possible_sums; for(auto [x,y] : possible_sums_not)possible_sums.pb({y,x}); sort(all(possible_sums)); reverse(all(possible_sums)); //~ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //~ shuffle(all(possible_sums), rng); for(auto [no_need, sum] : possible_sums){ unordered_map<int,int>cnt; for(i=1;i<=m;i++){ cnt[a[i]]++; } int have = 0; vector<int> v; for(i=1;i<=m;i++){ if(cnt[a[i]] <= 0)continue; if(a[i] >= sum)continue; if(sum-a[i] == a[i]){ if(cnt[sum - a[i]] > 1){ cnt[sum - a[i]]--; cnt[a[i]]--; have++; v.pb(a[i]); v.pb(sum-a[i]); } }else if(cnt[sum - a[i]] > 0){ cnt[sum - a[i]]--; cnt[a[i]]--; have++; v.pb(a[i]); v.pb(sum-a[i]); } } //~ cout << sum << ' ' << have << '\n'; if(have >= n/2){ sort(v.begin(), v.begin() + n); for(i=0;i<n;i++)cout << v[i] << ' ' ; cout << '\n'; return; } } } return; } /* 4 1 2 4 8 6 10 */ signed main(){ FASTIO; //~ #define MULTITEST 1 #if MULTITEST int _T; cin >> _T; for(int T_CASE = 1; T_CASE <= _T; T_CASE++) solve(T_CASE); #else solve(1); #endif 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...