This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pt;
int n, k, m;
const int maxn = 2e5+5;
const ll inf = 1e9+5;
int A[maxn];
map<int, int> mp;
bool chk(int x){
int l = 0, r = m-1, cnt = 0;
vector<int> vec;
while(l < r){
while(l < r && A[l]+A[r] > x)r--;
if(l==r)break;
if(A[l]+A[r] == x){
cnt++;
vec.push_back(A[l]);
vec.push_back(A[r]);
if(cnt == n/2){
sort(vec.begin(), vec.end());
for(auto v: vec)cout << v << " ";
return 1;
}
}
l++;
}
return 0;
}
int main(){
cin >> n >> k;
m = n+k;
//cout << m << "\n";
for(int i = 0; i < m; i++)cin >> A[i];
for(int i = 0; i < min(m, 2*k); i++){
for(int j = m-1; j >= max(m-2*k, i+1); j--){
mp[A[i]+A[j]]++;
}
}
for(auto v: mp)if(v.s >= min(k, n/2)){
if(chk(v.f))return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |