URAL 1728. Curse on Team.GOV

1728. Curse on Team.GOV

Time limit: 0.5 second
Memory limit: 64 MB
All the names in this problem are fictitious; the coincidences are accidental.
Long ago there was the Alarm team at the Ural State University. Its members Lyosha, Vadik, and Misha enjoyed going to programming contests instead of studying. In this composition the team participated in contests for a whole year. But once, after a conflict at a contest in Kazan, Lyosha and Vadik expelled Misha from the team and changed its name to Team.GOV.
After that, Lyosha and Vadik decided that the third member of the team would be Sasha. But he didn't come to the Ural SU Championship and said that he was very busy. Lyosha and Vadik had to participate in that contest without the third programmer. However, Sasha was not expelled from the team and took part in a subregional contest, which they lost. After that, the team “Lyosha, Vadik, Sasha” suddenly turned into the team “Vanya, Lyosha, Vadik” and went to the regional contest, which they also lost.
It is rumored that Team.GOV is cursed. After Alarm's break-up, the team composition is different at each contest.
An ICPC subregional contest is approaching, and the organizing committee obliged Lyosha and Vadik to find the third member of the team. Lyosha and Vadik compiled a list of candidates and calculated the rating of each candidate according to a secret formula. The power of the team is equal to the sum of the ratings of its members. Lyosha and Vadik want their team to be as powerful as possible. But the team is cursed… As the fates decree, if the team composition repeats a composition that once participated in some contest, Lyosha won't be able to come to the contest (and the power of the team will decrease by his rating). Even in this case, if this team composition (without Lyosha) participated in some contest earlier, Team.GOV will suddenly be disqualified during the practice session and won't take part in the contest. Help the permanent members of Team.GOV choose the third member so that the team will be as powerful as possible in the subregional contest.

Input

The first line contains the number of contests  n Team.GOV participated in (1 ≤  n ≤ 100). Each of the following  n lines describes one contest. The line starts with the number of the team's members that participated in the contest (an integer in the range from one to three). This number is followed by the space-separated list of last names of these members given in the alphabetical order. The names are different nonempty strings consisting of lowercase and uppercase English letters. The length of each name is at most 50. Lyosha's last name is Efremov and Vadik's last name is Kantorov. It is guaranteed that Vadik is present in all the compositions, and Lyosha is present in all the compositions consisting of three people. All the given compositions are different.
The following line contains space-separated integers  re and  rk  (1 ≤  rerk ≤ 666) . They are Lyosha's and Vadik's ratings, respectively. The following line contains the number  m of candidates who want to enter the team (1 ≤  m ≤ 100). Each of the following  m lines contains the last name and the rating of a candidate separated with a space. All the ratings are integers in the range from 1 to 666. All the last names are different. The list of candidates contains neither Lyosha nor Vadik.

Output

If, for any choice of the third member, Team.GOV will be disqualified, output the only line “Fail”. Otherwise, in the first line output “Win” and in the second line output the last name of the candidate who will become the third member of Team.GOV. If there are several possible answers, output any of them.

Samples

input output
6
3 Efremov Kantorov Rubinchik
2 Efremov Kantorov
3 Efremov Kantorov Kokovin
3 Burmistrov Efremov Kantorov
3 Efremov Kantorov Pervukhin
2 Kantorov Pervukhin
100 10
6
Fominykh 200
Komarov 34
Pervukhin 250
Golubev 23
Soboleva 50
Gein 50
Win
Fominykh
2
3 Efremov Fominykh Kantorov
2 Fominykh Kantorov
99 666
1
Fominykh 100
Fail





题意:有n次比赛。接下来n行,首先输入的是这场比赛有2个人或者三个人参加,然后是参加的人的名字。  接下来再输入Efr的rank,再输入Kan的rank。再输入m个候选人和他的rank。 一支队伍的战斗力是队伍里 每个人的rank和。接下来有一场比赛,Kan一定要参加,Efr可以不参加。问挑哪个候选人可以组成前n场比赛中没有组成过的阵容。如果无论哪种阵容,都曾经出现过在前n场比赛中输出fail。如果有新阵容,那么先输入win,在判断选哪个人可以形成最大的战斗力阵容。输出那个人名字。

题目看懂的话,基本就是模拟了。set和string的使用可以使代码更加简洁。

set<string> my2,my3;//存两个人组的时候不是kan的那个人名字,三人组的时候存不是Kan不是Efr的那个人名字
int main()
{
	int n,re,rk,m;
	while(cin>>n)
	{
		my2.clear();
		my3.clear();
		int flag=0;
		for(int i=0;i<n;i++)
		{
			int num;
			string name[3];
			string kk;
			cin>>num;
			kk="0";
			for(int j=0;j<num;j++)
			{
				cin>>name[j]; 
				if(name[j]!="Efremov"&&name[j]!="Kantorov")
					kk=name[j];
			} 
			if(num==2)
			{
				if(kk=="0")//自己两个人;
				{
					flag=1;
				}
				else//k带人
				{
					my2.insert(kk);
				} 
			}
			else if(num==3)
			{
				my3.insert(kk);

			}
		}
		cin>>re>>rk;
		cin>>m;
		int maxx=-1;
		string ansname;
		for(int i=0;i<m;i++)
		{
			string pp;
			int rat;
			cin>>pp>>rat; 
			if(my3.count(pp)==0&&rat+re+rk>maxx)
			{
				ansname=pp;
				maxx=rat+re+rk;
			}
			if(my2.count(pp)==0&&rat+rk>maxx)
			{
				ansname=pp;
				maxx=rat+rk; 
			}  
		}
		if(maxx==-1)
			puts("Fail");
		else
		{
			puts("Win");
			cout<<ansname<<endl; 
		} 
	}
	return 0; 
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值