Language: C++

//E? Nanndatte?
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int rec(vector<int>state[3],int a,int b)
{
	vector<int>_cur[3];
	for(int i=0;i<3;i++)
	{
		_cur[i]=state[i];
	}
	if(state[0].size()==a || state[2].size()==a) return 0;
	int s[3];
	for(int i=0;i<3;i++) s[i]=_cur[i].size();
	int val=INF;
	if(s[0])
	{
		if(s[1] && _cur[1][s[1]-1]<_cur[0][s[0]-1])
		{
			_cur[1].pb(_cur[0][s[0]-1]);
			_cur[0].pop_back();
			s[1]++;
			s[0]--;
			val=min(val,rec(_cur[3],a,b-1));
		}
		else if(s[1])
		{
			_cur[0].pb(_cur[1][s[1]-1]);
			_cur[1].pop_back();
			s[0]++;
			s[1]--;
			val=min(val,rec(_cur[3],a,b));
		}
	}
	if(s[2])
	{
		if(s[1] && _cur[1][s[1]-1]<_cur[2][s[2]-1])
		{
			_cur[1].pb(_cur[2][s[2]-1]);
			_cur[2].pop_back();
			s[1]++;
			s[2]--;
			val=min(val,rec(_cur[3],a,b));
		}
		else if(s[1])
		{
			_cur[2].pb(_cur[1][s[1]-1]);
			_cur[1].pop_back();
			s[2]++;
			s[1]--;
			val=min(val,rec(_cur[3],a,b));
		}
	}
	return val+1;
}
int main(){
	int n,k;
	while(1)
	{
		cin >> n >> k;
		if(n+k==0) return 0;
		vector<int>cur[3];
		for(int i=0;i<3;i++)
		{
			int f;
			cin >> f;
			cur[i].resize(0);
			for(int j=0;j<f;j++)
			{
				int d;
				cin >>d;
				cur[i].pb(d);
			}
		}
		int ans = rec(cur[3],n,k);
		if(ans>k) ans=-1;
		cout << ans << endl;
	}
}

Compiler output:
a.cc: In function 'int rec(std::vector<int>*, int, int)':
a.cc:43:47: error: cannot convert 'std::vector<int>' to 'std::vector<int>*'
   43 |                         val=min(val,rec(_cur[3],a,b-1));
      |                                         ~~~~~~^
      |                                               |
      |                                               std::vector<int>
a.cc:24:20: note:   initializing argument 1 of 'int rec(std::vector<int>*, int, int)'
   24 | int rec(vector<int>state[3],int a,int b)
      |         ~~~~~~~~~~~^~~~~~~~
a.cc:51:47: error: cannot convert 'std::vector<int>' to 'std::vector<int>*'
   51 |                         val=min(val,rec(_cur[3],a,b));
      |                                         ~~~~~~^
      |                                               |
      |                                               std::vector<int>
a.cc:24:20: note:   initializing argument 1 of 'int rec(std::vector<int>*, int, int)'
   24 | int rec(vector<int>state[3],int a,int b)
      |         ~~~~~~~~~~~^~~~~~~~
a.cc:62:47: error: cannot convert 'std::vector<int>' to 'std::vector<int>*'
   62 |                         val=min(val,rec(_cur[3],a,b));
      |                                         ~~~~~~^
      |                                               |
      |                                               std::vector<int>
a.cc:24:20: note:   initializing argument 1 of 'int rec(std::vector<int>*, int, int)'
   24 | int rec(vector<int>state[3],int a,int b)
      |         ~~~~~~~~~~~^~~~~~~~
a.cc:70:47: error: cannot convert 'std::vector<int>' to 'std::vector<int>*'
   70 |                         val=min(val,rec(_cur[3],a,b));
      |                                         ~~~~~~^
      |                                               |
      |                                               std::vector<int>
a.cc:24:20: note:   initializing argument 1 of 'int rec(std::vector<int>*, int, int)'
   24 | int rec(vector<int>state[3],int a,int b)
      |         ~~~~~~~~~~~^~~~~~~~
a.cc: In function 'int main()':
a.cc:94:36: error: cannot convert 'std::vector<int>' to 'std::vector<int>*'
   94 |                 int ans = rec(cur[3],n,k);
      |                               ~~~~~^
      |                                    |
      |                                    std::vector<int>
a.cc:24:20: note:   initializing argument 1 of 'int rec(std::vector<int>*, int, int)'
   24 | int rec(vector<int>state[3],int a,int b)
      |         ~~~~~~~~~~~^~~~~~~~