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;
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(tab[r] + tab[l] < w && l >= r)
{
r++;
}
while(tab[r] + tab[l] > w && l >= r)
{
l--;
}
if(l >= r)
{
how_many_pairs++;
r++;
l--;
}
}
// cout << i << " " << j << "\n";
if(how_many_pairs >= n/2)
{
vector<int> wyn = {i,j};
r = i+1;
l = j-1;
while(l >= r)
{
while(tab[r] + tab[l] < w && l >= r)
{
r++;
}
while(tab[r] + tab[l] > w && l >= r)
{
l--;
}
if(l >= r)
{
if(size(wyn) != n)
{
wyn.pb(r);wyn.pb(l);
}
r++;
l--;
}
}
sort(all(wyn));
rep(i,n) cout << wyn[i]+1 << " ";
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... |