B. Qualifying Contest

题目连接:

http://www.codeforces.com/contest/659/problem/B

Description

Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m regions of Berland. The result of each of the participants of the qualifying competition is an integer score from 0 to 800 inclusive.

The team of each region is formed from two such members of the qualifying competition of the region, that none of them can be replaced by a schoolboy of the same region, not included in the team and who received a greater number of points. There may be a situation where a team of some region can not be formed uniquely, that is, there is more than one school team that meets the properties described above. In this case, the region needs to undertake an additional contest. The two teams in the region are considered to be different if there is at least one schoolboy who is included in one team and is not included in the other team. It is guaranteed that for each region at least two 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 in this region its formation requires additional contests.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 1 ≤ m ≤ 10 000, n ≥ 2m) — the number of participants of the qualifying contest and the number of regions in Berland.

Next n lines contain the description of the participants of the qualifying contest in the following format: Surname (a string of length from 1 to 10 characters and consisting of large and small English letters), region number (integer from 1 to m) and the number of points scored by the participant (integer from 0 to 800, inclusive).

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

Output

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

Sample Input

5 2

Ivanov 1 763

Andreev 2 800

Petrov 1 595

Sidorov 1 790

Semenov 2 503

Sample Output

Sidorov Ivanov

Andreev Semenov

Hint

题意

给你n个人,然后有m个地区,每个地区将会选出分数最高的两个人

如果分数最高的不止两个人的话,输出?

题解:

每个地区都排序一波就好了

然后比较一下第二和第三的分数,如果一样的话,就输出?

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
vector<pair<int,string> >S[maxn];
bool cmp(pair<int,string> A,pair<int,string> B)
{
return A.first>B.first;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
string s;int x,y;
cin>>s>>x>>y;
S[x].push_back(make_pair(y,s));
}
for(int i=1;i<=m;i++)sort(S[i].begin(),S[i].end(),cmp);
for(int i=1;i<=m;i++)
{
if(S[i].size()==2)cout<<S[i][0].second<<" "<<S[i][1].second<<endl;
else
{
if(S[i][2].first==S[i][1].first)cout<<"?"<<endl;
else cout<<S[i][0].second<<" "<<S[i][1].second<<endl;
}
}
}

Codeforces Round #346 (Div. 2) B. Qualifying Contest 水题的更多相关文章

  1. Codeforces Round #346 (Div. 2) B Qualifying Contest

    B. Qualifying Contest 题目链接http://codeforces.com/contest/659/problem/B Description Very soon Berland ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  6. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  7. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

  8. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  9. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

随机推荐

  1. Aragorn's Story 树链剖分+线段树 && 树链剖分+树状数组

    Aragorn's Story 来源:http://www.fjutacm.com/Problem.jsp?pid=2710来源:http://acm.hdu.edu.cn/showproblem.p ...

  2. usb_submit_urb 解释的够够的

    /** * usb_submit_urb - issue an asynchronous transfer request for an endpoint * @urb: pointer to the ...

  3. Entity Framework 5.0 Code First全面学习 (转)

    原文地址:感谢原文作者 http://blog.csdn.net/gentle_wolf/article/details/14004345 不贴图片了,太累. Code First 约定 借助 Cod ...

  4. Pandas Installation

    1. 将环境变量PATH中加入C:\python2*\Scripts 或者 C:\Program Files\Python 3.5\Scripts 2. 进入pip.exe所在的目录:C:\Progr ...

  5. Python+Selenium 自动化实现实例-模块化调用

    public 目录存一些公共模块,供用例调用.login.py 内容如下: # coding=utf-8 import time # login def login(driver): driver.f ...

  6. linux shell 一些命令

    https://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash wc: https: ...

  7. 洛谷P1482 Cantor表(升级版) 题解

    题目传送门 此题zha一看非常简单. 再一看特别简单. 最后瞟一眼,还是很简单. 所以在此就唠一下GCD大法吧: int gcd(int x,int y){ if(x<y) return gcd ...

  8. Ant, JUnit以及Sonar的安装+入门资料

    Ant 感觉是个和Make/Grunt类似的东东,build一个项目用的.安装很容易,跟装JDK类似,就是解压->设环境变量->没了.注意装之前要先确认Java装好了(有点废话). 下载地 ...

  9. fastdfs5.11+centos7.2 按照部署(一)【转载】

    1.绪论 最近要用到fastDFS,所以自己研究了一下,在搭建FastDFS的过程中遇到过很多的问题,为了能帮忙到以后搭建FastDFS的同学,少走弯路,与大家分享一下.FastDFS的作者淘宝资深架 ...

  10. ajax json 学习笔记

    json = { } JSON 字符串必须使用双引号,单引号会出现错误 三种类型: 简单值:字符串.数值.布尔值.null 对象:无序的键值对儿 数组:有序的值列表 解析:JSON.eval()   ...