B. Qualifying Contest

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.

Input

Ivanov
Andreev
Petrov
Sidorov
Semenov

Output

Sidorov Ivanov
Andreev Semenov

Input

Ivanov
Andreev
Petrov
Sidorov
Semenov

Output

?
Andreev Semenov

心得:学会了vector中套结构体。。。。。。。。。。。

AC代码:

 #include<bits/stdc++.h>

 using namespace std;
#define endl '\n'
#define N 100009
struct str{
string name;
int team;
int score;
};
vector<str> v[N];
bool cmp(str a,str b){
return a.score>b.score;
}
int main(){
int n,m;
cin>>n>>m;
struct str temp;
for(int i=;i<=n;i++){
cin>>temp.name>>temp.team>>temp.score;
v[temp.team].push_back(temp);
}
for(int i=;i<=m;i++){
sort(v[i].begin(),v[i].end(),cmp);
if(v[i].size()==){
puts("?");
}else if(v[i].size()==){
cout<<v[i][].name<<" "<<v[i][].name<<endl;
}else{
if(v[i][].score==v[i][].score){
puts("?");
}else{
cout<<v[i][].name<<" "<<v[i][].name<<endl;
}
}
}
return ;
}

最新文章

  1. Oracle PL/SQL随堂笔记总结
  2. [No0000AA]Windows 系统环境变量列表
  3. Java反射机制的作用
  4. XproerIM V1,2,12,65376 发布。
  5. iOS开发-迭代器模式
  6. 8种NOsql
  7. iOS开发——技术精华Swift篇&amp;Swift 2.0和Objective-C2.0混编之第三方框架的使用
  8. php pdo(二)
  9. Linux 新手常用命令
  10. 调用Response.Redirect 捕获异常 解决办法(摘抄)
  11. Android之利用正则表达式校验邮箱、手机号、密码、身份证号码等
  12. Docker_部署jenkins(dockerfile实现)
  13. ms16-032漏洞复现过程
  14. Codeforces Round #539 Div1 题解
  15. Python3 与 C# 面向对象之~继承与多态
  16. HTTP中的重定向和请求转发的区别(转)
  17. android active间数据传递
  18. [转载]Oracle数据库基础--SQL查询经典例题
  19. LeetCode--232--用栈实现队列
  20. Linux之压缩与解压缩

热门文章

  1. ubuntu下java的安装与执行
  2. Netty源码剖析-接受数据
  3. Centos7下,宿主机nginx配合docker环境的php-fpm
  4. linux fork进程请谨慎多个进程/线程共享一个 socket连接,会出现多个进程响应串联的情况。
  5. MySQL的安装 --windows版本
  6. redis集群搭建及一些问题
  7. Secret的三种形式
  8. Delphi编译器属性(特别修饰符Ref,Unsafe,Volatile,Weak)
  9. 我是如何将一个加载90s的接口优化到不足2s的
  10. scala中ClassOf、asInstenceOf、isInstanceOf三个预定义方法分析