#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using pi = pair<int,int>;
#define ST first
#define ND second
#define PB push_back
const int nax = 150 * 1000 + 10 + 400;
int n, k;
int w[nax];
int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n + k; ++i) cin >> w[i];
for(int l = 0; l <= k; ++l) {
for(int r = 0; r + l <= k; ++r) {
int lt = k - (l + r);
int a = l + 1, b = n + k - r;
int sum = w[a] + w[b];
vi ans = {a, b};
bool ok = 1;
while(a + 1 < b) {
a++;
b--;
while(w[a] + w[b] != sum) {
if(w[a] + w[b] > sum) {
b--;
lt--;
if(lt < 0) {
ok = 0;
break;
}
} else {
a++;
lt--;
if(lt < 0) {
ok = 0;
break;
}
}
}
ans.PB(a);
ans.PB(b);
if(!ok) break;
}
if(ok) {
while(lt > 0) {
ans.pop_back();
ans.pop_back();
lt -= 2;
}
sort(ans.begin(), ans.end());
for(int x : ans) cout << w[x] << " ";
return 0;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
768 KB |
Output is correct |
2 |
Correct |
148 ms |
4588 KB |
Output is correct |
3 |
Correct |
149 ms |
4588 KB |
Output is correct |
4 |
Correct |
148 ms |
4744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
3052 KB |
Output is correct |
2 |
Correct |
150 ms |
4584 KB |
Output is correct |
3 |
Correct |
148 ms |
4584 KB |
Output is correct |
4 |
Correct |
149 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
154 ms |
4696 KB |
Output is correct |
3 |
Correct |
149 ms |
4588 KB |
Output is correct |
4 |
Correct |
147 ms |
4584 KB |
Output is correct |
5 |
Correct |
148 ms |
4588 KB |
Output is correct |
6 |
Correct |
151 ms |
4716 KB |
Output is correct |
7 |
Correct |
147 ms |
4588 KB |
Output is correct |
8 |
Correct |
149 ms |
4584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
169 ms |
4604 KB |
Output is correct |
3 |
Correct |
149 ms |
4588 KB |
Output is correct |
4 |
Correct |
164 ms |
4588 KB |
Output is correct |
5 |
Correct |
146 ms |
4588 KB |
Output is correct |
6 |
Correct |
150 ms |
4584 KB |
Output is correct |
7 |
Correct |
194 ms |
4716 KB |
Output is correct |
8 |
Correct |
148 ms |
4716 KB |
Output is correct |