Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define all(v) v.begin(), v.end()

struct node {
  int a, b, c;
  ll v;
  node(int x, int y, int z, ll w) : a(x), b(y), c(z), v(w) {}
  bool operator<(auto b) const {
    return v < b.v;
  }
};

vector<ll> a, b, c;

node calc(int x, int y, int z)
{
  node n(x, y, z, a[x] + b[y] + c[z]);
  return n;
}

int main()
{
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  a.resize(x);
  b.resize(y);
  c.resize(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(all(a), greater<ll>());
  sort(all(b), greater<ll>());
  sort(all(c), greater<ll>());
  priority_queue<node, vector<node>, greater<node>> q;
  q.push(calc(0, 0, 0));
  set<node> s;
  s.insert(calc(0, 0, 0));
  while (1) {
    if (k == 0) break;
    auto a = q.top();
    q.pop();
    cout << a.v << endl;
    if (s.count(calc(a.x+1, a.y, a.z)) == 0) {
      q.push(calc(a.x+1, a.y, a.z));
      s.insert(calc(a.x+1, a.y, a.z));
    }
    if (s.count(calc(a.x, a.y+1, a.z)) == 0) {
      q.push(calc(a.x, a.y+1, a.z));
      s.insert(calc(a.x, a.y+1, a.z));
    }
    if (s.count(calc(a.x, a.y, a.z+1)) == 0) {
      q.push(calc(a.x, a.y, a.z+1));
      s.insert(calc(a.x, a.y, a.z+1));
    }
    k--;
  }
}



Compiler output:
a.cc:14:18: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   14 |   bool operator<(auto b) const {
      |                  ^~~~
a.cc: In function 'int main()':
a.cc:49:24: error: 'struct node' has no member named 'x'
   49 |     if (s.count(calc(a.x+1, a.y, a.z)) == 0) {
      |                        ^
a.cc:49:31: error: 'struct node' has no member named 'y'
   49 |     if (s.count(calc(a.x+1, a.y, a.z)) == 0) {
      |                               ^
a.cc:49:36: error: 'struct node' has no member named 'z'
   49 |     if (s.count(calc(a.x+1, a.y, a.z)) == 0) {
      |                                    ^
a.cc:50:21: error: 'struct node' has no member named 'x'
   50 |       q.push(calc(a.x+1, a.y, a.z));
      |                     ^
a.cc:50:28: error: 'struct node' has no member named 'y'
   50 |       q.push(calc(a.x+1, a.y, a.z));
      |                            ^
a.cc:50:33: error: 'struct node' has no member named 'z'
   50 |       q.push(calc(a.x+1, a.y, a.z));
      |                                 ^
a.cc:51:23: error: 'struct node' has no member named 'x'
   51 |       s.insert(calc(a.x+1, a.y, a.z));
      |                       ^
a.cc:51:30: error: 'struct node' has no member named 'y'
   51 |       s.insert(calc(a.x+1, a.y, a.z));
      |                              ^
a.cc:51:35: error: 'struct node' has no member named 'z'
   51 |       s.insert(calc(a.x+1, a.y, a.z));
      |                                   ^
a.cc:53:24: error: 'struct node' has no member named 'x'
   53 |     if (s.count(calc(a.x, a.y+1, a.z)) == 0) {
      |                        ^
a.cc:53:29: error: 'struct node' has no member named 'y'
   53 |     if (s.count(calc(a.x, a.y+1, a.z)) == 0) {
      |                             ^
a.cc:53:36: error: 'struct node' has no member named 'z'
   53 |     if (s.count(calc(a.x, a.y+1, a.z)) == 0) {
      |                                    ^
a.cc:54:21: error: 'struct node' has no member named 'x'
   54 |       q.push(calc(a.x, a.y+1, a.z));
      |                     ^
a.cc:54:26: error: 'struct node' has no member named 'y'
   54 |       q.push(calc(a.x, a.y+1, a.z));
      |                          ^
a.cc:54:33: error: 'struct node' has no member named 'z'
   54 |       q.push(calc(a.x, a.y+1, a.z));
      |                                 ^
a.cc:55:23: error: 'struct node' has no member named 'x'
   55 |       s.insert(calc(a.x, a.y+1, a.z));
      |                       ^
a.cc:55:28: error: 'struct node' has no member named 'y'
   55 |       s.insert(calc(a.x, a.y+1, a.z));
      |                            ^
a.cc:55:35: error: 'struct node' has no member named 'z'
   55 |       s.insert(calc(a.x, a.y+1, a.z));
      |                                   ^
a.cc:57:24: error: 'struct node' has no member named 'x'
   57 |     if (s.count(calc(a.x, a.y, a.z+1)) == 0) {
      |                        ^
a.cc:57:29: error: 'struct node' has no member named 'y'
   57 |     if (s.count(calc(a.x, a.y, a.z+1)) == 0) {
      |                             ^
a.cc:57:34: error: 'struct node' has no member named 'z'
   57 |     if (s.count(calc(a.x, a.y, a.z+1)) == 0) {
      |                                  ^
a.cc:58:21: error: 'struct node' has no member named 'x'
   58 |       q.push(calc(a.x, a.y, a.z+1));
      |                     ^
a.cc:58:26: error: 'struct node' has no member named 'y'
   58 |       q.push(calc(a.x, a.y, a.z+1));
      |                          ^
a.cc:58:31: error: 'struct node' has no member named 'z'
   58 |       q.push(calc(a.x, a.y, a.z+1));
      |                               ^
a.cc:59:23: error: 'struct node' has no member named 'x'
   59 |       s.insert(calc(a.x, a.y, a.z+1));
      |                       ^
a.cc:59:28: error: 'struct node' has no member named 'y'
   59 |       s.insert(calc(a.x, a.y, a.z+1));
      |                            ^
a.cc:59:33: error: 'struct node' has no member named 'z'
   59 |       s.insert(calc(a.x, a.y, a.z+1));
      |                                 ^
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = node]':
/usr/include/c++/14/bits/predefined_ops.h:196:23:   required from 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<node*, std::vector<node> >; _Value = node; _Compare = std::greater<node>]'
  196 |         { return bool(_M_comp(*__it, __val)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<node*, vector<node> >; _Distance = long int; _Tp = node; _Compare = __gnu_cxx::__ops::_Iter_comp_val<greater<node> >]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:216:23:   required from 'void std::push_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<node*, vector<node> >; _Compare = greater<node>]'
  216 |       std::__push_heap(__first, _DistanceType((__last - __first) - 1),
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |                        _DistanceType(0), _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:747:16:   required from 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = node; _Sequence = std::vector<node>; _Compare = std::greater<node>; value_type = node]'
  747 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:41:9:   required from here
   41 |   q.push(calc(0, 0, 0));
      |   ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:395:20: error: no match for 'operator>' (operand types are 'const node' and 'const node')
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const node' is not derived from 'const std::pair<_T1, _T2>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const node' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const node' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const node' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const node' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~