Language: C++

#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;

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<long long> 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());
	reverse(A.begin(), A.end());
	sort(B.begin(), B.end());
	reverse(B.begin(), B.end());
	sort(C.begin(), C.end());
	reverse(C.begin(), C.end());

	priority_queue<pair<long long, Nums>> pq;
	pq.push(make_pair(A[0] + B[0] + C[0], Nums(0, 0, 0)));
	set<int> s;
	s.insert(0);

	vector<long long> 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()) {
				s.insert(hash);
				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()) {
				s.insert(hash);
				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;
			int c = v.second.c + 1;
			//hashを作る
			int hash = (a << 20) + (b << 10) + c;
			if (s.find(hash) == s.end()) {
				s.insert(hash);
				pq.push(make_pair(A[a] + B[b] + C[c], Nums(a, b, c)));
			}
		}

	}

	for (int i = 0; i < K; i++)
	{
		cout << ans[i] << endl;
	}

}



Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:43:9:   required from here
   43 |         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:20:14: note: candidate: 'bool Nums::operator<(const Nums&)' (near match)
   20 |         bool operator<(const Nums& other) {
      |              ^~~~~~~~
a.cc:20:14: note:   passing 'const Nums*' as 'this' argument discards qualifiers
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448: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::reverse_iterator<_Iterator>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493: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::reverse_iterator<_Iterator>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694: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::move_iterator<_IteratorL>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760: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::move_iterator<_IteratorL>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/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); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~