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 <iostream>
using namespace std;
const int nmax = 150000;
const int kmax = 400;
int a[nmax + kmax];
int n, k;
pair < int, int > ans[nmax / 2];
int check ( int sum ) {
int st = 0, dr = n + k - 1, cnt = 0;
while ( st < dr && cnt < n / 2 && st < dr ) {
if ( a[st] + a[dr] == sum )
ans[cnt++] = { st++, dr-- };
else if ( a[st] + a[dr] < sum )
st++;
else dr--;
}
return cnt >= n / 2;
}
int main() {
cin >> n >> k;
for ( int i = 0; i < n + k; i++ )
cin >> a[i];
bool ok = false;
for ( int i = 0; i <= k && !ok; i++ )
for ( int j = n - 1; j < n + k && !ok; j++ )
if ( i < j && check ( a[i] + a[j] ) )
ok = true;
for ( int i = 0; i < n / 2; i++ )
cout << a[ans[i].first] << ' ';
for ( int i = n / 2 - 1; i >= 0; i-- )
cout << a[ans[i].second] << ' ';
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... |