题目链接:

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. hdu 4862 KM算法 最小K路径覆盖的模型

    http://acm.hdu.edu.cn/showproblem.php?pid=4862 选t<=k次,t条路要经过全部的点一次而且只一次. 建图是问题: 我自己最初就把n*m 个点分别放入 ...

  2. 跟我一起写 Makefile(一)[转]

    原文链接 http://bbs.chinaunix.net/thread-408225-1-1.html(出处: http://bbs.chinaunix.net/) 陈皓 概述—— 什么是makef ...

  3. uva 11404 dp

    UVA 11404 - Palindromic Subsequence 求给定字符串的最长回文子序列,长度一样的输出字典序最小的. 对于 [l, r] 区间的最长回文串.他可能是[l+1, r] 和[ ...

  4. attr/attrs模块

    attr简介 开源库,提供了为函数或类提供更直接的创建属性的方法. Github or PyPi 用法 from attr import attrs, attrib @attrs class Foo: ...

  5. 15 redis 之 aof恢复与rdb服务器间迁移

    三:常见的问题 BGREWRITEAOF 后台进程重写AOF BGSAVE 后台保存rdb快照 SAVE 保存rdb快照 LASTSAVE 上次保存时间 Slaveof master-Host por ...

  6. 【文献阅读】Augmenting Supervised Neural Networks with Unsupervised Objectives-ICML-2016

    一.Abstract 从近期对unsupervised learning 的研究得到启发,在large-scale setting 上,本文把unsupervised learning 与superv ...

  7. IT痴汉的工作现状10-Sprint Planning

    这是我们的第四个Sprint了.因为上一个迭代周期的失利,Leader群发邮件这样描写叙述道:"对任务的乐观预计,导致Sprint 3没有如期完毕. 我们须要在这次Sprint计划中细致评估 ...

  8. EasyNVR NVR网页无插件直播在兼容宇视NVR RTSP流媒体时PLAY过程对Scale的兼容

    前一段在维护EasyNVR客户的过程中遇到一个问题,在接入宇视NVR的时候,就是明明在vlc中能非常正常播放的视频流,却用EasyRTSPClient RTSP客户端拉流的协议交互过程中,PLAY命令 ...

  9. MongoDB在win7上的安装(精简版)

    1.下载mongdb的zip文件,解压后会发现有bin文件夹,在同层目录下建一个data目录, 2.在data目录下建一个log和db文件夹, 3.在log文件下建一个MongoDB.log 文件 4 ...

  10. Linux Tomcat的安装

    inux版本:CentOS 6.2 iso文件下载地址:http://mirrors.163.com/centos/6.2/isos/i386/CentOS-6.2-i386-bin-DVD1.iso ...