오류 버전(통과는 됐음)

~cpp
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

struct table
{
	int Num;
	int maxNum;
};

struct team
{
	int Num;
	int maxNum;
	vector<int> tableNum;
};

int tableNum, teamNum, i, j, k, l;
team temp1;
table temp2;
vector<table> test_table;
vector<team> test_team;

bool compare_table(const table & a,const table & b)
{
	return a.maxNum > b.maxNum;
}

bool compare_team_max(const team & a,const team & b)
{
	return a.maxNum > b.maxNum;
}

bool compare_team_num(const team & a,const team & b)
{
	return a.Num < b.Num;
}

void process()
{
	int totalcount = 0;
	bool check = true;
	sort(test_table.begin(),test_table.end(), compare_table);
	sort(test_team.begin(), test_team.end(), compare_team_max);
	for(i = 0; i < test_team.size(); i ++)
	{

		if(test_team[i].maxNum >= test_table.size())
		{
			totalcount++;
			for(j = 0; j < test_table.size(); j++)
				test_team[i].tableNum.push_back(j+1);
			if(test_team[i].maxNum == 2* test_table.size())
			{
				totalcount++;
				for(j = 0; j < test_table.size(); j++)
					test_team[i].tableNum.push_back(j+1);
			}
		}
		
		for(j = 0; j < test_team[i].maxNum % test_table.size(); j++)
		{
			test_table[j].maxNum--;
			test_team[i].tableNum.push_back(test_table[j].Num);
		}

		for(j = 0; j < test_table.size(); j++)
		{	
			if(test_table[j].maxNum - totalcount < 0)
				check = false;
		}
		if(check == false)
			break;
		sort(test_table.begin(),test_table.end(), compare_table);
	}

	if(check)
	{
		cout << "1" << endl;
		sort(test_team.begin(), test_team.end(), compare_team_num);
		for(i = 0; i < test_team.size(); i++)
		{
			sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end());
			for(j = 0; j < test_team[i].maxNum; j++)
				cout << test_team[i].tableNum[j] << " ";
			cout << endl;
		}
	}
	else
		cout << "0" << endl;

}
int main()
{
	while(true)
	{
		cin >> teamNum >> tableNum;
		if( tableNum == 0 && teamNum == 0)
			break;
		for(i = 0; i < teamNum;i++)
		{
			temp1.Num = i + 1;
			cin >> temp1.maxNum;
			test_team.push_back(temp1);
		}
		for(i = 0; i < tableNum; i++)
		{
			temp2.Num = i + 1;
			cin >> temp2.maxNum;
			test_table.push_back(temp2);
		}
		process();
		test_team.clear();
		test_table.clear();
	}

	return 0;
}

수정판

~cpp
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>

struct table
{
	int Num;
	int maxNum;
};

struct team
{
	int Num;
	int maxNum;
	vector<int> tableNum;
};

int tableNum, teamNum, i, j, k, l;
team temp1;
table temp2;
vector<table> test_table;
vector<team> test_team;

bool compare_table(const table & a,const table & b)
{
	return a.maxNum > b.maxNum;
}

bool compare_team_max(const team & a,const team & b)
{
	return a.maxNum > b.maxNum;
}

bool compare_team_num(const team & a,const team & b)
{
	return a.Num < b.Num;
}

void process()
{
	int maxtable = test_table.size();
	int temp1;
	bool check = true;
	sort(test_table.begin(),test_table.end(), compare_table);
	sort(test_team.begin(), test_team.end(), compare_team_max);
	for(i = 0; i < test_team.size(); i ++)
	{		
		if(test_team[i].maxNum > maxtable)
		{
			check = false;
			break;				
		}
		else
		{
			for(j = 0; j < test_team[i].maxNum; j++)
			{
				test_table[j].maxNum--;
				test_team[i].tableNum.push_back(test_table[j].Num);
			}
			
			test_team[i].maxNum = 0;
			
			temp1 = maxtable;
			for(j = 0; j < temp1; j++)
			{	
				if(test_table[j].maxNum == 0)
					maxtable--;
			}
			sort(test_table.begin(),test_table.end(), compare_table);			
		}
	}

	if(check)
	{
		cout << "1" << endl;
		sort(test_team.begin(), test_team.end(), compare_team_num);
		for(i = 0; i < test_team.size(); i++)
		{
			sort(test_team[i].tableNum.begin(),test_team[i].tableNum.end());
			for(j = 0; j < test_team[i].tableNum.size(); j++)
				cout << test_team[i].tableNum[j] << " ";
			cout << endl;
		}
	}
	else
		cout << "0" << endl;

}
int main()
{
	while(true)
	{
		cin >> teamNum >> tableNum;
		if( tableNum == 0 && teamNum == 0)
			break;
		for(i = 0; i < teamNum;i++)
		{
			temp1.Num = i + 1;
			cin >> temp1.maxNum;
			test_team.push_back(temp1);
		}
		for(i = 0; i < tableNum; i++)
		{
			temp2.Num = i + 1;
			cin >> temp2.maxNum;
			test_table.push_back(temp2);
		}
		process();
		test_team.clear();
		test_table.clear();
	}

	return 0;
}

Retrieved from http://wiki.zeropage.org/wiki.php/TheGrandDinner/김상섭
last modified 2021-02-07 05:28:11