#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int a[2137];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin >> n >> k;
for (int x=1;x<=n+k;x++) cin >> a[x];
set<int> dp[n+k+9][n+k+9][k+9];
dp[1][n+k][0].insert(0);
int wybr = -1;
for (int x=1;x<=n+k;x++){
for (int y=n+k;y>=x;y--){
for (int z=0;z<=k;z++){
for (int w:dp[x][y][z]){
if (w==0) dp[x+1][y-1][z].insert(a[x]+a[y]);
if (w==a[x]+a[y]) dp[x+1][y-1][z].insert(w);
if (z<k){
dp[x+1][y][z+1].insert(w);
dp[x][y-1][z+1].insert(w);
}
}
}
}
}
/*for (int x=1;x<=n+k;x++){
for (int y=1;y<=n+k;y++){
for (int z=0;z<=k;z++){
if (dp[x][y][z].empty())continue;
cout << x << ' ' << y << ' ' << z << ": ";
for (int w:dp[x][y][z]) cout << w << ' ';
cout << '\n';
}
}
}*/
for (int x=1;x<n+k;x++){
for (int w:dp[x+1][x][k]){
wybr=w;
break;
}
}
//cout << "wybr: " << wybr << '\n';
vector<int> odp;
map<int,int> cnt;
for (int x=1;x<=n+k;x++) cnt[a[x]]++;
int zost=n;
for (int x=1;x<=n+k;x++){
if (zost==0) break;
if (cnt[a[x]]>0 && cnt[wybr-a[x]]>0){
cnt[a[x]]--;
cnt[wybr-a[x]]--;
odp.push_back(a[x]);
odp.push_back(wybr-a[x]);
zost-=2;
}
}
//cout << "odp" << '\n';
sort(odp.begin(),odp.end());
for (int x:odp) cout << x << ' ';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
532 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
829 ms |
330084 KB |
Output is correct |
2 |
Correct |
882 ms |
440240 KB |
Output is correct |
3 |
Correct |
858 ms |
440048 KB |
Output is correct |
4 |
Correct |
841 ms |
440200 KB |
Output is correct |
5 |
Correct |
829 ms |
440272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
860 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
509 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2908 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
521 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |