题目链接:

B. Qualifying Contest

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 1to 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.

Examples
input
5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
output
Sidorov Ivanov
Andreev Semenov
input
5 2
Ivanov 1 800
Andreev 2 763
Petrov 1 800
Sidorov 1 800
Semenov 2 503
output
?
Andreev Semenov
Note

In the first sample region teams are uniquely determined.

In the second sample the team from region 2 is uniquely determined and the team from region 1 can have three teams: "Petrov"-"Sidorov", "Ivanov"-"Sidorov", "Ivanov" -"Petrov", so it is impossible to determine a team uniquely.

题意:

给这么人的名字,来自的地区和分数,从每个地区选分数最高的两个人,要求其他人的分数都比他两小;

思路:

按地区和分数排序,再判断第二名和第三名的分数就好啦;

AC代码:

/*
2014300227 659B - 45 GNU C++11 Accepted 577 ms 8432 KB
*/
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
struct node
{
string str;
int pos,num;
};
node po[N];
int cmp(node x,node y)
{
if(x.pos==y.pos)return x.num>y.num;
return x.pos<y.pos;
}
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
{
cin>>po[i].str>>po[i].pos>>po[i].num;
}
sort(po,po+n,cmp);
if(po[].pos==po[].pos)
{
if(po[].num==po[].num)cout<<"?"<<"\n";
else cout<<po[].str<<" "<<po[].str<<"\n";
}
else
{
cout<<po[].str<<" "<<po[].str<<"\n";
}
po[n].pos=po[n-].pos;
po[n].num=-;
for(int i=;i<n-;i++)
{
if(po[i].pos==po[i-].pos)continue;
if(po[i+].pos==po[i+].pos)
{
if(po[i+].num==po[i+].num)cout<<"?"<<"\n";
else cout<<po[i].str<<" "<<po[i+].str<<"\n";
}
else cout<<po[i].str<<" "<<po[i+].str<<"\n";
}
return ;
}

codeforces 659B B. Qualifying Contest(水题+sort)的更多相关文章

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

    B. Qualifying Contest 题目连接: http://www.codeforces.com/contest/659/problem/B Description Very soon Be ...

  2. CodeForces 681A A Good Contest (水题)

    题意:给定 n 个人和before, after的分数,让你找 before 的分数大于等于2400并且before 小于 after. 析:看完题意就知道怎么算了吧..不用说了 #include & ...

  3. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  4. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  5. CodeForces 489B BerSU Ball (水题 双指针)

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  8. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  9. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

随机推荐

  1. 对于Json和对象转换的学习

    学习这个的用处有非常多的:        在传输数据过程中比較查看数据比較清晰,代码也较清晰.也能够避免split函数带来的隐藏bug 当然也有不足:        准备工具较繁琐,须要准备对象(当然 ...

  2. React学习之受控和非受控组件

    受控组件是通过事件完成对元素value的控制,反之就是非受控组件. 1.受控组件的value通过onChange事件来改变,非受控不需要通过事件来改变value. 2.受控组件通过事件通过setSta ...

  3. java类库中的设计模式

    原帖:http://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns 提问:我正在学习GoF的<设计模式&g ...

  4. Struts2学习四----------动态方法调用

    © 版权声明:本文为博主原创文章,转载请注明出处 Struts2动态方法调用 - 默认:默认执行方法中的execute方法,若指定类中没有该方法,默认返回success <package nam ...

  5. php nginx超时出错

    执行PHP操作大文件insert mysql数据库时,出现这个错误提示 The page you are looking for is temporarily unavailable.Please t ...

  6. javascript的defer和async(转载)

    http://ued.ctrip.com/blog/?p=3121 我们常用的javascript标签,有两个和性能.js文件下载执行相关的属性:defer和async defer的含义[摘自http ...

  7. Android NDK开发初步

    在配置好NDK开发之后就能够使用C/C++开发android了.以下以一个HelloWorld项目来说明 1.新建一个Androidproject 新建一个HelloWorldproject 代码例如 ...

  8. 自己动手写CPU之第七阶段(2)——简单算术操作指令实现过程

    将陆续上传本人写的新书<自己动手写CPU>.今天是第25篇.我尽量每周四篇 亚马逊的预售地址例如以下,欢迎大家围观呵! http://www.amazon.cn/dp/b00mqkrlg8 ...

  9. 搭建sftp服务+nginx代理

    在公司,经常会用到sftp服务,比如两个公司对接生产项目,其中一方,要在sftp上上传pdf文件,另一方公司要在sftp服务器上用nginx代理直接下载pdf文件.下面就说说我在实际中应用到的sftp ...

  10. t60替换alt,super,ctrl

    发现T60的左边在ctrl 与 alt 有个win 键,所以就进行了映射 网上有一个把alt->ctrl, super-> alt, ctrl->super的script, 见 ht ...