#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
const int mxN = 150001;
const int mxK = 401;
int N, K;
int A[mxN];
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> K;
FOR(i,1,N+K){
cin >> A[i];
}
FOR(i,1,K+1){
RFOR(j,N+K,N+i-1){
int mx = min(j-i+1-N, K-(i-1)-(N+K-j));
//TRACE(i _ j _ mx);
int l = i, r = j;
int a = i+1, b = j-1, c = 0;
vector<int> ls = {l}, rs = {r};
while (SZ(ls)+SZ(rs) < N && a < b && c <= mx) {
int cur = A[a]+A[b], tgt = A[l]+A[r];
//TRACE(a _ b _ cur _ tgt);
if (cur == tgt) {
l = a, r = b;
ls.push_back(a++);
rs.push_back(b--);
} else {
if (cur < tgt) ++a, ++c;
else --b, ++c;
}
}
//TRACE(SZ(ls) _ SZ(rs) _ c);
if (SZ(ls)+SZ(rs) == N) {
for (int& x : ls) cout << A[x] << ' ';
reverse(ALL(rs));
for (int& x : rs) cout << A[x] << ' ';
return 0;
}
}
}
assert(false);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
716 KB |
Output is correct |
2 |
Execution timed out |
3079 ms |
844 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3089 ms |
844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Execution timed out |
3090 ms |
872 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
20 ms |
1636 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |