#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(x) x.begin(),x.end()
const int MOD = 1e9 + 7, SZ = 1e5 + 10, MX = 1e9;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
int arr[n + k];
for(int &i : arr)
cin >> i;
ll a[k + 1], b[k + 1];
for(int i=0;i<=k;i++)
a[i] = arr[i];
reverse(arr, arr + n + k);
for(int i=0;i<=k;i++)
b[i] = arr[i];
map<int, int> mp;
vector<int> f;
int mx = 0;
for(ll i : a){
for(ll j : b){
if(i == j)
continue;
mx = max(mx, ++mp[i + j]);
f.push_back(i + j);
}
}
vector<int> vec;
for(int i : f){
if(mp[i] == mx)
vec.push_back(i);
}
reverse(arr, arr + n + k);
for(ll i : vec){
vector<int> ans;
int l = 0, r = n + k - 1;
while(l < r){
ll x = arr[l] + arr[r];
if(ans.size() == n)
break;
if(x == i){
ans.push_back(arr[l]);
ans.push_back(arr[r]);
}
if(x >= i)
r--;
if(x <= i)
l++;
}
if(ans.size() == n){
sort(all(ans));
for(int x : ans)
cout << x << ' ';
break;
}
}
return 0;
}
// https://www.youtube.com/watch?v=zL32whN6p0A&ab_channel=HeidiAdel-CartoonWorld
Compilation message
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:42:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if(ans.size() == n)
| ~~~~~~~~~~~^~~~
tabletennis.cpp:53:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if(ans.size() == n){
| ~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
732 KB |
Output is correct |
2 |
Correct |
34 ms |
3028 KB |
Output is correct |
3 |
Correct |
32 ms |
3064 KB |
Output is correct |
4 |
Correct |
32 ms |
3072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3036 KB |
Output is correct |
2 |
Correct |
43 ms |
3016 KB |
Output is correct |
3 |
Correct |
32 ms |
3064 KB |
Output is correct |
4 |
Correct |
30 ms |
3004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
724 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
5324 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |