B. Qualifying Contest_ Sort

Source: Internet
Author: User

B. Qualifying ContestTime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Very soon Berland would hold a School Team programming Olympiad. From each of the m Berland regions A team of the people are invited to participate in the Olympiad. The qualifying contest to form teams is held and it is attended by N berland students. There were at least, schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is a integer score from 0 to inclusive.< /c8>

The team of each of the such members of the qualifying competition in the region, and that none of the them Can is replaced by a schoolboy of the same region, not included in the team and who received A greater number of points. There may was a situation where a team of some region can isn't being formed uniquely, that's, there is more than one school te Am that meets the properties described above. In this case, the region needs to undertake an additional contest. The "teams in the" considered to be different if there was at least one schoolboy who was included in one team And is not a included in the other team. It is guaranteed this for each region at least and its representatives participated in the qualifying contest.

Your task is, given the results of the qualifying competition, to identify the team from each region, or to announce that Formation requires additional contests.


The first line of the input contains the integers n and m (2≤ n ≤100, 1≤ m ≤10, n ≥2m)-the number of participants of the qualifying contest and the Numbe R of Regions in Berland.

Next n lines contain the description of the participants of the qualifying contest in the following format:s Urname (a string of length from 1to characters and consisting of large and small 中文版 letters), Region Numbe R (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800 , inclusive).

It is guaranteed this all surnames of the participants be distinct and at least, people participated from each of The m regions. The surnames that is differ in letter cases, should is considered distinct.


Print m lines. On the i-th line print the team of the i-th region-the surnames of the both team members Arbitrary order, or a single character "?" (without the quotes) if you need to spend further qualifying contests in the region.

5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
Sidorov Ivanov
Andreev Semenov
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
Andreev Semenov

Problem Solving Report:

1, the topic is very simple, is to see test instructions, the idea output Oh!

#include <map>#include<stack>#include<vector>#include<queue>#include<Set>#include<cmath>#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<string>using namespaceStd;typedefLong LongLl;vector<pair<int,string> > v[100005];intn,m;BOOLcmpConstpair<int,string>&a,Constpair<int,string>&b) {    if(a.first==B.first)returnA.second>B.second; Else returnA.first>B.first;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) v[i].clear ();  for(intI=1; i<=n;i++)    {        intId,score; Charname[ -]; scanf ("%s%d%d",name,&id,&score);    V[id].push_back (Make_pair (score,name)); }     for(intI=1; i<=m;i++) sort (V[i].begin (), V[i].end (), CMP);  for(intI=1; i<=m;i++)    {        if(v[i][0].first==v[i][1].first) {if(v[i].size () = =2|| v[i][1].first>v[i][2].first) printf ("%s%s\n", v[i][0].second.c_str (), v[i][1].second.c_str ()); ElsePuts"?"); Continue; }        if(v[i].size () = =2|| v[i][1].first>v[i][2].first) printf ("%s%s\n", v[i][0].second.c_str (), v[i][1].second.c_str ()); ElsePuts"?"); }    return 0;}

B. Qualifying Contest_ Sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.