Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

class Nums{
    public:
        int a, b, c;
    Nums(int _a,int _b, int _c){
        a = _a;
        b = _b;
        c = _c;
    }
    bool operator <(const Nums &other){
        return a < other.a;
    }
};

int main ()
{
    int X,Y,Z;
    int K;
    cin>>X>>Y>>Z;
    cin>>K;
    vector<ll> A(X),B(Y),C(Z);
    for(int i = 0; i < X; i++)  cin>>A[i];
    for(int i = 0; i < Y; i++)  cin>>B[i];
    for(int i = 0; i < Z; i++)  cin>>C[i];
    sort(A.begin(),A.end(),greater<ll>());
    sort(B.begin(),B.end(),greater<ll>());
    sort(C.begin(),C.end(),greater<ll>());
    priority_queue <pair<ll,Nums>>pq;
    pq.push(make_pair(A[0]+B[0]+C[0],Nums(0,0,0)));
    set<ll> s;
    s.insert(0);
    vector<ll> ans;
    while(ans.size()<K){
        auto v = pq.top();pq.pop();
        ans.push_back(v.first);
        if(v.second.a != X-1){
            int a = v.second.a + 1;
            int b = v.second.b;
            int c = v.second.c;
            //hashをつくり重複を管理
            int hash = (a<<20) + (b<<10) + c;
            if(s.find(hash) == s.end()){
                pq.push(make_pair(A[a]+B[b]+C[c],Nums(a,b,c)));
            }
        }
         if(v.second.b != Y-1){
            int a = v.second.a ;
            int b = v.second.b + 1;
            int c = v.second.c;
            //hashをつくり重複を管理
            int hash = (a<<20) + (b<<10) + c;
            if(s.find(hash) == s.end()){
                pq.push(make_pair(A[a]+B[b]+C[c],Nums(a,b,c)));
            }
        }
         if(v.second.c != Z-1){
            int a = v.second.a;
            int b = v.second.b + 1;
            int c = v.second.c;
            //hashをつくり重複を管理
            int hash = (a<<20) + (b<<10) + c;
            if(s.find(hash) == s.end()){
                pq.push(make_pair(A[a]+B[b]+C[c],Nums(a,b,c)));
            }
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    REP(i,K){
        cout<<ans[i]<<endl;
    }


    return 0;
}

Compiler output:
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,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h: In instantiation of 'constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&) [with _T1 = long long int; _T2 = Nums]':
/usr/include/c++/14/bits/stl_function.h:405:20:   required from 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::pair<long long int, Nums>]'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/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<std::pair<long long int, Nums>*, std::vector<std::pair<long long int, Nums>, std::allocator<std::pair<long long int, Nums> > > >; _Value = std::pair<long long int, Nums>; _Compare = std::less<std::pair<long long int, Nums> >]'
  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<pair<long long int, Nums>*, vector<pair<long long int, Nums>, allocator<pair<long long int, Nums> > > >; _Distance = long int; _Tp = pair<long long int, Nums>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<less<pair<long long int, Nums> > >]'
  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<pair<long long int, Nums>*, vector<pair<long long int, Nums>, allocator<pair<long long int, Nums> > > >; _Compare = less<pair<long long int, Nums> >]'
  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 = std::pair<long long int, Nums>; _Sequence = std::vector<std::pair<long long int, Nums>, std::allocator<std::pair<long long int, Nums> > >; _Compare = std::less<std::pair<long long int, Nums> >; value_type = std::pair<long long int, Nums>]'
  747 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:12:   required from here
   40 |     pq.push(make_pair(A[0]+B[0]+C[0],Nums(0,0,0)));
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1047:57: error: no match for 'operator<' (operand types are 'const Nums' and 'const Nums')
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
a.cc:21:10: note: candidate: 'bool Nums::operator<(const Nums&)' (near match)
   21 |     bool operator <(const Nums &other){
      |          ^~~~~~~~
a.cc:21:10: note:   passing 'const Nums*' as 'this' argument discards qualifiers
/usr/include/c++/14/bits/stl_pair.h:1045:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1045 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Nums' is not derived from 'const std::pair<_T1, _T2>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~