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>
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define size(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace std;
//mt19937 mt;void random(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll rand(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
ll tab[150400];
void solve()
{
int n,k;
cin >> n >> k;
rep(i,n+k)
{
cin >> tab[i];
}
//sort(tab,tab+(n+k));
for(int i = 0; i <= k; i++)
{
for(int j = n+k-1; j >= n-1; j--)
{
if(i == j) continue;
int r = i+1;
int l = j-1;
ll w = tab[i] + tab[j];
// cout << i << " " << j << " " << w << "\n";
int how_many_pairs = 1;
while(l > r)
{
while(l > r && tab[r] + tab[l] < w)
{
r++;
}
while(l > r && tab[r] + tab[l] > w)
{
l--;
}
if(l > r && tab[r] + tab[l] == w)
{
how_many_pairs++;
r++;
l--;
}
else break;
}
// cout << i << " " << j << "\n";
if(how_many_pairs >= n/2)
{
vector<ll> wyn = {tab[i],tab[j]};
r = i+1;
l = j-1;
while(l > r)
{
while(l > r && tab[r] + tab[l] < w)
{
r++;
}
while(l > r && tab[r] + tab[l] > w)
{
l--;
}
if(l > r)
{
if(size(wyn) != n)
{
wyn.pb(tab[r]);wyn.pb(tab[l]);
}
r++;
l--;
}
}
sort(all(wyn));
rep(i,n) cout << wyn[i] << " ";
return;
}
}
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// random();
int t = 1;
// cin >> t;
while(t--) solve();
}
# | 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... |