#include <bits/stdc++.h>
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int ll
typedef long long ll;
using namespace std;
const int N = 15e4 + 10, mod = 1e9 + 7;
int n, k, a[N];
map<int, bool> vis;
map<int, vector<pair<int, int> > > mp;
void solve() {
int ch1 = a[0] + a[n+k-1], ch2 = a[0] + a[n+k-2], ch3 = a[1] + a[n+k-1];
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
for(int i = 0; i < n + k; i++) {
if(vis[ch1 - a[i]]) cnt1++;
if(vis[ch2 - a[i]]) cnt2++;
if(vis[ch3 - a[i]]) cnt3++;
}
int num = 0;
if(cnt1 >= cnt2 && cnt1 >= cnt3) num = ch1;
else if(cnt2 >= cnt1 && cnt2 >= cnt3) num = ch2;
else num = ch3;
int dont = a[n+k-1];
for(int i = 0; i < n + k; i++) {
if(vis[num - a[i]]) cout << a[i] << ' ';
}
return;
}
// 2 + 2 = 4
// 4 + 2 = 6
void solve1() {
vector<int> v;
int cnt[100];
for(int i = 0; i < 100; i++) cnt[i] = 0;
if(n + k == 4) for(int i = 0; i < n + k; i++) v.push_back(a[i]);
else {
v.push_back(a[0]);
v.push_back(a[1]);
v.push_back(a[2]);
v.push_back(a[n+k-1]);
v.push_back(a[n+k-2]);
v.push_back(a[n+k-3]);
}
set<int> s;
for(int i = 0; i < v.size(); i++) {
for(int j = 0; j < v.size(); j++) {
s.insert(v[i] + v[j]);
}
}
vector<int> nums;
for(auto it : s) nums.push_back(it);
int num = 0, cur = 0;
for(int i = 0; i < n + k; i++) {
for(int j = 0; j < nums.size(); j++) {
if(vis[nums[j] - a[i]]) cnt[j]++;
if(cnt[j] > cur) {
cur = cnt[j];
num = nums[j];
}
}
}
set<pair<int, int> > ans;
for(int i = 0; i < n + k; i++) {
if(vis[num - a[i]]) ans.insert({min(num-a[i], a[i]), max(num-a[i], a[i])});
}
vector<int> fin;
for(auto it : ans) {
if(fin.size() == n) break;
fin.push_back(it.first);
fin.push_back(it.second);
}
sort(fin.begin(), fin.end());
for(int it : fin) cout << it << ' ';
return;
}
void solve2() {
set<int> v;
int cnt[1000];
for(int i = 0; i < 1000; i++) cnt[i] = 0;
for(int i = 0; i < k + 1; i++) if(i < n + k) v.insert(a[i]);
for(int i = n + k - 1; i >= (n + k - 1) - k; i--) if(i >= 0) v.insert(a[i]);
set<int> s;
for(auto i : v) {
for(auto j : v) {
s.insert(i + j);
}
}
vector<int> nums;
for(auto it : s) nums.push_back(it);
int num = 0, cur = 0;
for(int i = 0; i < (n + k) / 2 + 21; i++) {
for(int j = 0; j < nums.size(); j++) {
if(vis[nums[j] - a[i]]) cnt[j]++;
if(cnt[j] > cur) {
cur = cnt[j];
num = nums[j];
}
}
}
set<pair<int, int> > ans;
for(int i = 0; i < n + k; i++) {
if(vis[num - a[i]]) ans.insert({min(num-a[i], a[i]), max(num-a[i], a[i])});
}
vector<int> fin;
for(auto it : ans) {
if(fin.size() == n) break;
fin.push_back(it.first);
fin.push_back(it.second);
}
sort(fin.begin(), fin.end());
for(int it : fin) cout << it << ' ';
return;
}
signed main() {
FAST;
cin >> n >> k;
int num = 0;
for(int i = 0; i < n + k; i++) {
cin >> a[i];
vis[a[i]] = 1;
}
if(k == 1) {
solve();
return 0;
}
if(k == 2) {
solve1();
return 0;
}
if(k <= 20) {
solve2();
return 0;
}
for(int i = 0; i < n + k - 1; i++) {
for(int j = i + 1; j < n + k; j++) {
mp[a[i] + a[j]].push_back({a[i], a[j]});
if(mp[a[i] + a[j]].size() >= n / 2) num = a[i] + a[j];
}
}
vector<int> v;
int i = 0;
while(v.size() < n && i < mp[num].size()) {
v.push_back(mp[num][i].first);
v.push_back(mp[num][i].second);
i++;
}
sort(v.begin(), v.end());
for(auto it : v) {
cout << it << ' ';
}
}
Compilation message
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:23:9: warning: unused variable 'dont' [-Wunused-variable]
23 | int dont = a[n+k-1];
| ^~~~
tabletennis.cpp: In function 'void solve1()':
tabletennis.cpp:45:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
tabletennis.cpp:46:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int j = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
tabletennis.cpp:54:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j = 0; j < nums.size(); j++) {
| ~~^~~~~~~~~~~~~
tabletennis.cpp:68:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
68 | if(fin.size() == n) break;
| ~~~~~~~~~~~^~~~
tabletennis.cpp: In function 'void solve2()':
tabletennis.cpp:92:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for(int j = 0; j < nums.size(); j++) {
| ~~^~~~~~~~~~~~~
tabletennis.cpp:106:23: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
106 | if(fin.size() == n) break;
| ~~~~~~~~~~~^~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:137:39: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
137 | if(mp[a[i] + a[j]].size() >= n / 2) num = a[i] + a[j];
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
tabletennis.cpp:142:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
142 | while(v.size() < n && i < mp[num].size()) {
| ~~~~~~~~~^~~
tabletennis.cpp:142:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | while(v.size() < n && i < mp[num].size()) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
724 KB |
Output is correct |
2 |
Correct |
2 ms |
596 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1824 KB |
Output is correct |
2 |
Correct |
140 ms |
31116 KB |
Output is correct |
3 |
Correct |
151 ms |
31080 KB |
Output is correct |
4 |
Correct |
142 ms |
31108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
847 ms |
168208 KB |
Output is correct |
2 |
Correct |
1113 ms |
196608 KB |
Output is correct |
3 |
Correct |
846 ms |
182904 KB |
Output is correct |
4 |
Correct |
1077 ms |
196196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1236 KB |
Output is correct |
2 |
Correct |
6 ms |
2004 KB |
Output is correct |
3 |
Correct |
6 ms |
1996 KB |
Output is correct |
4 |
Correct |
6 ms |
2004 KB |
Output is correct |
5 |
Correct |
5 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Correct |
97 ms |
16884 KB |
Output is correct |
3 |
Correct |
260 ms |
58160 KB |
Output is correct |
4 |
Correct |
153 ms |
41536 KB |
Output is correct |
5 |
Correct |
105 ms |
16932 KB |
Output is correct |
6 |
Incorrect |
26 ms |
2364 KB |
Unexpected end of file - int32 expected |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1108 KB |
Output is correct |
2 |
Runtime error |
56 ms |
21844 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
10408 KB |
Output is correct |
2 |
Runtime error |
48 ms |
21776 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |