이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int 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--)
{
// cout << i << " " << j << "\n";
int r = i+1;
int l = j-1;
int w = tab[i] + tab[j];
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)
{
how_many_pairs++;
r++;
l--;
}
}
// cout << i << " " << j << "\n";
if(how_many_pairs >= n/2)
{
vector<int> 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... |