Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
using namespace std;
long long f(vector<vector<long long>> cake,vector<int> pos)
{
	long long sum = 0;
	for(int i=0; i<3; i++)
	{
		sum+=cake[i][pos[i]];
	}
	return sum;
}
int getflag(vector<vector<vector<int>>> flag ,vector<int> pos)
{
	return flag[pos[0]][pos[1]][pos[2]];
}
void setflag(vector<vector<vector<int>>>& flag ,vector<int> pos,int value)
{
	flag[pos[0]][pos[1]][pos[2]]=value;
}
bool fflag(set<vector<int>> flag,vector<long long> pos)
{
	if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
	{
		return false;
	}
	return true;
}
int main()
{
	vector<int> size(3);
	for(int i=0; i<3; i++)
	{
		cin>>size[i];
	}

	set<vector<long long>> flag;
	

	int K;
	cin>>K;
	vector<vector<long long>> cake;
	cake.resize(3);
	for(int i=0; i<3; i++)
	{
		cake[i].resize(size[i]);
		for(int j=0; j<size[i]; j++)
		{
			cin>>cake[i][j];
		}
	}
	for(int i=0; i<3; i++)
	{
		sort(cake[i].begin(),cake[i].end(),greater<long long>());
	}
	priority_queue<pair<long long,vector<int>>> q;
	vector<int> initial{0,0,0};
	q.push(make_pair(f(cake,initial),initial));
	flag.insert(0);
	for(int k=0; k<K; k++)
	{
		
		cout<<q.top().first<<endl;
		vector<int> list = q.top().second;
		
		q.pop();
		if(k==K-1)
		{
			break;
		}
		
		vector<vector<int>> next(3);
		next[0] = {list[0]+1,list[1],list[2]};
		next[1] = {list[0],list[1]+1,list[2]};
		next[2] = {list[0],list[1],list[2]+1};

		for(int i=0; i<3; i++)
		{
			if(list[i]+1>=size[i] || fflag(flag,next[i][0]*1000000+next[i][1]*1000+next[i][2]))
			{
				continue;
			}
			q.push(make_pair(f(cake,next[i]),next[i]));
			flag.insert(next[i]);
		}
	}
	return 0;
}

Compiler output:
a.cc: In function 'bool fflag(std::set<std::vector<int> >, std::vector<long long int>)':
a.cc:33:21: error: no matching function for call to 'std::set<std::vector<int> >::find(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)'
   33 |         if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from a.cc:10:
/usr/include/c++/14/bits/stl_set.h:806:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::iterator{((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) [with _Key = std::vector<int>; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::vector<int> >]'
  806 |         find(const _Kt& __x)
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:806:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<std::vector<int> >::iterator{((std::set<std::vector<int> >*)this)->std::set<std::vector<int> >::_M_t.std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(__x)}) std::set<std::vector<int> >::find(const _Kt&) [with _Kt = long long int]':
a.cc:33:14:   required from here
   33 |         if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:807:45: error: no matching function for call to 'std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(const long long int&)'
  807 |         -> decltype(iterator{_M_t._M_find_tr(__x)})
      |                              ~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/set:62:
/usr/include/c++/14/bits/stl_tree.h:1291:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) [with _Req = _Kt; _Key = std::vector<int>; _Val = std::vector<int>; _KeyOfValue = std::_Identity<std::vector<int> >; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::vector<int> >]'
 1291 |         _M_find_tr(const _Kt& __k)
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/14/string:49,
                 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_function.h: In substitution of 'template<class _Func, class _SfinaeType> using std::__has_is_transparent_t = typename std::__has_is_transparent<_Func, _SfinaeType>::type [with _Func = std::less<std::vector<int> >; _SfinaeType = long long int]':
/usr/include/c++/14/bits/stl_tree.h:1289:9:   required by substitution of 'template<class _Kt> decltype (std::set<std::vector<int> >::iterator{((std::set<std::vector<int> >*)this)->std::set<std::vector<int> >::_M_t.std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(__x)}) std::set<std::vector<int> >::find(const _Kt&) [with _Kt = long long int]'
 1289 |                typename _Req = __has_is_transparent_t<_Compare, _Kt>>
      |                ^~~~~~~~
a.cc:33:14:   required from here
   33 |         if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:1427:11: error: no type named 'type' in 'struct std::__has_is_transparent<std::less<std::vector<int> >, long long int, void>'
 1427 |     using __has_is_transparent_t
      |           ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<std::vector<int> >::iterator{((std::set<std::vector<int> >*)this)->std::set<std::vector<int> >::_M_t.std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(__x)}) std::set<std::vector<int> >::find(const _Kt&) [with _Kt = long long int]':
a.cc:33:14:   required from here
   33 |         if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1300:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) const [with _Req = _Kt; _Key = std::vector<int>; _Val = std::vector<int>; _KeyOfValue = std::_Identity<std::vector<int> >; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::vector<int> >]'
 1300 |         _M_find_tr(const _Kt& __k) const
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1300:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h:806:9: error: no matching function for call to 'std::_Rb_tree_const_iterator<std::vector<int> >::_Rb_tree_const_iterator(<brace-enclosed initializer list>)'
  806 |         find(const _Kt& __x)
      |         ^~~~
/usr/include/c++/14/bits/stl_tree.h:346:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator(const iterator&) [with _Tp = std::vector<int>; iterator = std::_Rb_tree_const_iterator<std::vector<int> >::iterator]'
  346 |       _Rb_tree_const_iterator(const iterator& __it) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:346:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:343:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator(_Base_ptr) [with _Tp = std::vector<int>; _Base_ptr = const std::_Rb_tree_node_base*]'
  343 |       _Rb_tree_const_iterator(_Base_ptr __x) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:343:7: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:339:7: note: candidate: 'std::_Rb_tree_const_iterator<_Tp>::_Rb_tree_const_iterator() [with _Tp = std::vector<int>]'
  339 |       _Rb_tree_const_iterator() _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:339:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/stl_tree.h:324:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<std::vector<int> >::_Rb_tree_const_iterator(const std::_Rb_tree_const_iterator<std::vector<int> >&)'
  324 |     struct _Rb_tree_const_iterator
      |            ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:324:12: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_tree.h:324:12: note: candidate: 'constexpr std::_Rb_tree_const_iterator<std::vector<int> >::_Rb_tree_const_iterator(std::_Rb_tree_const_iterator<std::vector<int> >&&)'
/usr/include/c++/14/bits/stl_tree.h:324:12: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_set.h:812:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::const_iterator{((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) const [with _Key = std::vector<int>; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::vector<int> >]'
  812 |         find(const _Kt& __x) const
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:812:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (std::set<std::vector<int> >::const_iterator{((const std::set<std::vector<int> >*)this)->std::set<std::vector<int> >::_M_t.std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(__x)}) std::set<std::vector<int> >::find(const _Kt&) const [with _Kt = long long int]':
a.cc:33:14:   required from here
   33 |         if(flag.find(pos[0]*1000000+pos[1]*1000+pos[2]) == flag.end())
      |            ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:813:51: error: no matching function for call to 'std::_Rb_tree<std::vector<int>, std::vector<int>, std::_Identity<std::vector<int> >, std::less<std::vector<int> >, std::allocator<std::vector<int> > >::_M_find_tr(const long long int&) const'
  813 |         -> decltype(const_iterator{_M_t._M_find_tr(__x)})
      |                                    ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) [with _Req = _Kt; _Key = std::vector<int>; _Val = std::vector<int>; _KeyOfValue = std::_Identity<std::vector<int> >; _Compare = std::less<std::vector<int> >; _Alloc = std::allocator<std::vector<int> >]'
 1291 |         _M_find_tr(const _Kt& __k)
      |         ^~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:1291:9: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_tree.h:1300:9: note: candidate: 'template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_find_tr(const _Kt&) const [with _