제출 #486853

#제출 시각아이디문제언어결과실행 시간메모리
486853couplefireTable Tennis (info1cup20_tabletennis)C++17
100 / 100
345 ms33044 KiB
#include <bits/stdc++.h> using namespace std; int n, k, m, arr[200405]; void check(int sum){ vector<int> res; for(int l = 0, r = m-1; l<r;){ if(arr[l]+arr[r]==sum) res.push_back(arr[l]), res.push_back(arr[r]), ++l, --r; else if(arr[l]+arr[r]<sum) ++l; else --r; } while((int)res.size()>n) res.pop_back(); if((int)res.size()<n) return; sort(res.begin(), res.end()); for(auto x : res) cout << x << ' '; cout << '\n'; exit(0); } int main(){ // freopen("a.in", "r", stdin); cin.tie(0)->sync_with_stdio(0); cin >> n >> k; m = n+k; for(int i = 0; i<m; ++i) cin >> arr[i]; sort(arr, arr+m); vector<int> todo; if(m<4*k){ for(int i = 0; i<m; ++i) for(int j = i+1; j<m; ++j) todo.push_back(arr[i]+arr[j]); sort(todo.begin(), todo.end()); todo.erase(unique(todo.begin(), todo.end()), todo.end()); } else{ map<int, int> cnt; for(int i = 0; i<2*k; ++i) for(int j = 0; j<2*k; ++j) cnt[arr[i]+arr[m-1-j]]++; for(auto [x, y] : cnt) if(y>=k) todo.push_back(x); } for(auto x : todo) check(x); }
#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...