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;
const int dimN = 15 * 1e4;
const int dimK = 400;
int v[1 + dimN + dimK], sol[1 + dimN];
int n, k;
int check(int l,int r)
{
int ind = r - (n + l - 1);
int sum = v[l] + v[r];
sol[1] = v[l];
sol[n] = v[r];
l++;
r--;
int val=1;
while (l < r && ind >= 0){
if (v[l] + v[r] == sum){
val++;
sol[val] = v[l];
sol[n - val + 1] = v[r];
l++;
r--;
} else if (v[l] + v[r] < sum){l++;ind--;}
else{r--;ind--;}
}
return val;
}
int main()
{
cin >> n >> k;
for (int i = 0; i < n + k; i++){cin >> v[i];}
for (int i = 0; i < k + 1; i++){
bool verif = 0;
for (int j = n + i - 1; j < n + k; j++){
int l=i,r=j;
if (check(l,r) == n / 2){
verif = true;
break;
}
}
if (verif)break;
}
for (int i = 1; i <= n; i++){
cout << sol[i] << " ";
}
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... |