1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, pair<int, int>> iii;
const int N = 3333;
ll inpX[N], inpY[N], inpZ[N];
struct Node {
int x, y, z;
bool operator<(const Node &others) const
{
ll s1 = inpX[x] + inpY[y] + inpZ[z];
ll s2 = inpX[others.x] + inpY[others.y] + inpZ[others.z];
return s1 < s2;
}
ll val()
{
return inpX[x] + inpY[y] + inpZ[z];
}
};
int main()
{
int x, y, z, k;
scanf("%d %d %d %d", &x, &y, &z, &k);
for (int i = 0; i < x; i++)
scanf("%lld", &inpX[i]);
sort(inpX, inpX + x);
for (int i = 0; i < y; i++)
scanf("%lld", &inpY[i]);
sort(inpY, inpY + y);
for (int i = 0; i < z; i++)
scanf("%lld", &inpZ[i]);
sort(inpZ, inpZ + z);
priority_queue<Node> pq;
set<iii> used;
used.insert({x - 1, {y - 1, z - 1}});
pq.push({x - 1, y - 1, z - 1});
while (pq.size() > 0 && k--) {
Node cur = pq.top();
pq.pop();
printf("%lld\n", cur.val());
if (cur.x > 0) {
auto newNode = cur;
newNode.x--;
iii c = {newNode.x, {newNode.y, newNode.z}};
if (used.find(c) == used.end())
pq.push(newNode), used.insert(c);
}
if (cur.y > 0) {
auto newNode = cur;
newNode.y--;
iii c = {newNode.x, {newNode.y, newNode.z}};
if (used.find(c) == used.end())
pq.push(newNode), used.insert(c);
}
if (cur.z > 0) {
auto newNode = cur;
newNode.z--;
iii c = {newNode.x, {newNode.y, newNode.z}};
if (used.find(c) == used.end())
pq.push(newNode), used.insert(c);
}
}
return 0;
}
|