URAL 1728. Curse on Team.GOV

来源:互联网 发布:淘宝女装主图制作方法 编辑:程序博客网 时间:2024/04/28 00:50

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

inputoutput
63 Efremov Kantorov Rubinchik2 Efremov Kantorov3 Efremov Kantorov Kokovin3 Burmistrov Efremov Kantorov3 Efremov Kantorov Pervukhin2 Kantorov Pervukhin100 106Fominykh 200Komarov 34Pervukhin 250Golubev 23Soboleva 50Gein 50
WinFominykh
23 Efremov Fominykh Kantorov2 Fominykh Kantorov99 6661Fominykh 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; }



0 0