URAL 1728. Curse on Team.GOV(STL set)
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1728
1728. Curse on Team.GOV
Time limit: 0.5 second
Memory limit: 64 MB
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
≤ re, rk ≤ 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 |
代码例如以下:
#include <cstdio> #include <cstring> #include <string> #include <set> #include <iostream> #include <algorithm> using namespace std; set<string>m2, m3; int main() { int n, m; string s; while(~scanf("%d",&n)) { for(int i = 0; i < n; i++) { cin >> m; for(int j = 0; j < m; j++) { cin >> s; if(s != "Kantorov" && s != "Efremov") { if(m == 2) { m2.insert(s); } else if(m == 3) { m3.insert(s); } } } } int pe, pk; int q, power; string qq; cin >> pe >> pk; cin >> q; string ans; int maxx = 0; for(int i = 0; i < q; i++) { cin >> qq >> power; if(m2.count(qq)==0 && pk+power > maxx) { ans = qq; maxx = pk+power; } if(m3.count(qq)==0 && pk+power+pe > maxx) { ans = qq; maxx = pk+power+pe; } } if(maxx == 0) { cout<<"Fail"<<endl; } else { cout<<"Win"<<endl; cout<<ans<<endl; } } return 0; }