#include<bits/stdc++.h>
using namespace std;
const int N = 155010;
int n, k, a[N];
map<int, int> mp;
bool check(int sum) {
vector <int> L, R;
int l = 1, r = n + k, cn = 0;
while (l < r) {
if (a[l] + a[r] > sum) {
if (cn == k) return 0;
--r;
++cn;
} else if (a[l] + a[r] < sum) {
if (cn == k) return 0;
++l;
++cn;
} else {
L.push_back(a[l]);
R.push_back(a[r]);
++l; --r;
}
}
for (int x : L) cout<<x<<' ';
reverse(R.begin(), R.end());
for (int x : R) cout<<x<<' ';
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n + k; ++i) {
cin >> a[i];
}
if (0) {
for (int i = 1; i < n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (check(a[i] + a[j])) {
return 0;
}
}
}
} else {
for (int i = 1; i <= 2 * k; ++i) {
for (int j = n - k + 1; j <= n + k; ++j) {
mp[a[i] + a[j]]++;
}
}
for (auto &ele : mp) {
if (ele.second >= k) {
if (check(ele.first)) return 0;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
808 KB |
Output is correct |
2 |
Correct |
33 ms |
3308 KB |
Output is correct |
3 |
Correct |
33 ms |
3180 KB |
Output is correct |
4 |
Correct |
37 ms |
3180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3180 KB |
Output is correct |
2 |
Correct |
33 ms |
3308 KB |
Output is correct |
3 |
Correct |
33 ms |
3308 KB |
Output is correct |
4 |
Correct |
35 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
768 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Incorrect |
0 ms |
384 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
324 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
5496 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |