#include <algorithm>
#include <iostream>
#include <fstream>
#include <queue>
#include <cmath>
#define fi first
#define se second
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
using namespace std;
using pii = pair<int, int>;
const int NMAX = 15e4+5;
int n, k;
int a[NMAX];
vector<int> ans;
void read() {
cin >> n >> k;
for (int i = 1; i <= n + k; i++) {
cin >> a[i];
}
}
bool check(vector<int> a) {
if (sz(a) == 2) return a[0] == a[1];
sort(all(a));
if (sz(a) / 2 % 2 == 0) {
for (int i = 0; i < sz(a) / 2; i++)
a[i] += a[sz(a) - i - 1];
a.resize(sz(a) / 2);
} else {
for (int i = 0; i < sz(a) / 2 - 1; i++)
a[i] += a[sz(a) - i - 1];
a.resize(sz(a) / 2 + 1);
}
return check(a);
}
void solve() {
if (k == 1) {
vector<int> v;
for (int i = 1; i <= n; i++)
v.push_back(a[i]);
for (int i = 0; i < n; i++) {
if (i != n - 1)
swap(v[i], v[n - 1]);
if (check(v)) {
ans = v;
break;
}
if (i != n - 1)
swap(v[i], v[n - 1]);
}
} else {
for (int mask = 1; mask < 1 << (n + k); mask++) {
if (__builtin_popcount(mask) != n) continue;
vector<int> v;
for (int i = 0; i < n + k; i++) {
if (mask & (1 << i))
v.push_back(a[i + 1]);
}
if (check(v)) {
ans = v;
break;
}
}
}
sort(all(ans));
for (auto &it : ans) {
cout << it << ' ';
}
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output does not have symmetry property |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3013 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
1060 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3047 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |