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 x, y, z;
  ll v;
  node(int a, int b, int c, ll d) : x(a), y(b), z(c), v(d) {}
  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 {
      |                  ^~~~
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; }
      |                ~~~~^~~~~