Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef pair<ll,P> lP;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template <class T>struct PairingHeap{
    struct node{
        T key;
        node *head,*next;
        explicit node(T key):key(key),head(nullptr),next(nullptr){}
    };
    node *r;
    PairingHeap():r(nullptr){}
    PairingHeap(node* r):r(r){}
    node* merge(node *a,node *b){
        if(!a||!b) return a?a:b;
        if(a->key<b->key){
            b->next=a->head,a->head=b;
            return a;
        }
        else{
            a->next=b->head,b->head=a;
            return b;
        }
    }
    node* mergelist(node *s){
        if(!s) return nullptr;
        node h(0);
        while(s){
            node *a=s,*b=nullptr;
            s=s->next;a->next=nullptr;
            if(s) b=s,s=s->next,b->next=nullptr;
            a=merge(a,b);a->next=h.next;
            h.next=a;
        }
        node *t=h.next;
        s=t;
        t=t->next;
        while(t){
            node *u=t;
            t=t->next;
            s=merge(s,u);
        }
        return s;
    }
    T top(){
        if(!r) return numeric_limits<T>::min();
        return r->key;
    }
    void pop(){
        if(!r) return;
        r=mergelist(r->head);
    }
    void push(T k){r=merge(r,new node(k));}
    bool empty(){return !r;}
};

int main(){
    ll x,y,z,k,a[1010],b[1010],c[1010],ans,S,X,Y,Z,cnt=0;
    cin>>x>>y>>z>>k;
    fr(i,x) cin>>a[i];
    fr(i,y) cin>>b[i];
    fr(i,z) cin>>c[i];
    sort(a,a+x);
    sort(b,b+y);
    sort(c,c+z);
    reverse(a,a+x);
    reverse(b,b+y);
    reverse(c,c+z);
    ans=a[0]+b[0]+c[0];
    ifr(i,x) a[i]=a[0]-a[i];
    ifr(i,y) b[i]=b[0]-b[i];
    ifr(i,z) c[i]=c[0]-c[i];
    PairingHeap<PP> pq;
    pq.push(mp(mp(0,0),mp(0,0)));
    map<lP,bool> lPb;
    while(cnt<k){
        PP pp=pq.top();
        pq.pop();
        if(lPb[mp(pp.ft.sd,pp.sd)]) continue;
        cout<<ans-pp.ft.ft<<endl;
        cnt++;
        lPb[mp(pp.ft.sd,pp.sd)]=1;
        S=pp.ft.ft;X=pp.ft.sd;Y=pp.sd.ft;Z=pp.sd.sd;
        if(X<x-1) pq.push(mp(mp(a[X+1]+b[Y]+c[Z],X+1),mp(Y,Z)));
        if(Y<y-1) pq.push(mp(mp(a[X]+b[Y+1]+c[Z],X),mp(Y+1,Z)));
        if(Z<z-1) pq.push(mp(mp(a[X]+b[Y]+c[Z+1],X),mp(Y,Z+1)));
    }
}


Compiler output:
a.cc: In instantiation of 'PairingHeap<T>::node* PairingHeap<T>::mergelist(node*) [with T = std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >]':
a.cc:63:11:   required from 'void PairingHeap<T>::pop() [with T = std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >]'
   63 |         r=mergelist(r->head);
      |           ^~~~~~~~~
a.cc:90:15:   required from here
   90 |         pq.pop();
      |         ~~~~~~^~
a.cc:39:14: error: no matching function for call to 'PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node::node(int)'
   39 |         node h(0);
      |              ^
a.cc:21:18: note: candidate: 'PairingHeap<T>::node::node(T) [with T = std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >]'
   21 |         explicit node(T key):key(key),head(nullptr),next(nullptr){}
      |                  ^~~~
a.cc:21:25: note:   no known conversion for argument 1 from 'int' to 'std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >'
   21 |         explicit node(T key):key(key),head(nullptr),next(nullptr){}
      |                       ~~^~~
a.cc:18:12: note: candidate: 'constexpr PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node::node(const PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node&)'
   18 |     struct node{
      |            ^~~~
a.cc:18:12: note:   no known conversion for argument 1 from 'int' to 'const PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node&'
a.cc:18:12: note: candidate: 'constexpr PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node::node(PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node&&)'
a.cc:18:12: note:   no known conversion for argument 1 from 'int' to 'PairingHeap<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::node&&'