codeforces659B
Qualifying Contest
Very soon Berland will hold a School Team Programming Olympiad. From each of the mBerland 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.
Examples
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
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.
sol:STL非常好用,按照分数从大到小排序后如果第二名分数和第三名相同就无法确定了
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,B=;
int n,m;
struct Record
{
char Name[B];
int Score;
};
inline bool cmp(Record p,Record q)
{
return p.Score>q.Score;
}
vector<Record>Vec[N];
char Name[B];
int main()
{
int i;
R(n); R(m);
for(i=;i<=n;i++)
{
Record tmp;
int id;
scanf("%s",tmp.Name);
R(id);
R(tmp.Score);
Vec[id].push_back(tmp);
}
for(i=;i<=m;i++)
{
sort(Vec[i].begin(),Vec[i].end(),cmp);
if(Vec[i].size()==)
{
puts("?");
}
else if(Vec[i].size()==)
{
printf("%s",Vec[i][].Name);
putchar(' ');
printf("%s",Vec[i][].Name);
putchar('\n');
}
else
{
if(Vec[i][].Score==Vec[i][].Score) puts("?");
else
{
printf("%s",Vec[i][].Name);
putchar(' ');
printf("%s",Vec[i][].Name);
putchar('\n');
}
}
}
return ;
}
/*
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
*/
codeforces659B的更多相关文章
随机推荐
- Android学习之基础知识十四 — Android特色开发之基于位置的服务
一.基于位置的服务简介 LBS:基于位置的服务.随着移动互联网的兴起,这个技术在最近的几年里十分火爆.其实它本身并不是什么时髦的技术,主要的工作原理就是利用无线电通讯网络或GPS等定位方式来确定出移动 ...
- UOJ67 新年的毒瘤 tarjan
题目传送门 题意:给出一个$N$个点.$M$条边的无向图,找出其中的点,满足去掉该点与和它相连的边之后,这个图会变成一棵树.$N , M \leq 10^5$ 说是毒瘤,真的不毒瘤 思考一下,我们需要 ...
- BootStrap学习(6)_模态框
一.模态框 模态框(Modal)是覆盖在父窗体上的子窗体.通常,目的是显示来自一个单独的源的内容,可以在不离开父窗体的情况下有一些互动.子窗体可提供信息.交互等. 如果只使用该功能,只引入BootSt ...
- [Oracle]跨DBLINK的JOIN查询的数据库缓存问题15783452141
客户问到跨DBLINK,结合本地表和远端表的时候,数据在哪一边 的 Data Buffer 缓存. 测试的结果是:本地表在本地缓存,远端表在远端缓存. ####Testcase-0929-10 本地数 ...
- PowerBI开发 第十五篇:DAX 表达式(时间+过滤+关系)
DAX表达式中包含时间关系(Time Intelligence)相关的函数,用于对日期维度进行累加.同比和环比等分析.PowerBI能够创建关系,通过过滤器来对影响计算的上下文. 一,时间关系 DAX ...
- 聊聊Zookeeper应用场景、架构设计、选主机制
Zookeeper作为一个分布式协调系统提供了一项基本服务:分布式锁服务,分布式锁是分布式协调技术实现的核心内容.像配置管理.任务分发.组服务.分布式消息队列.分布式通知/协调等,这些应用实际上都是基 ...
- NTP服务部署和测试
1. 概述2. 部署3. 配置4. 客户端配置4.1 客户端安装ntpdate4.2 同步设置 1. 概述 本篇博客主要记录如何部署一台NTP服务器,用于内网时间同步. 时间服务器对于集群内部节点之间 ...
- React之父子组件传递和其它一些要点
react是R系技术栈中最基础同时也是最核心的一环,2年不到获取了62.5k star(截止到目前),足可见其给力程度.下面对一些react日常开发中的注意事项进行罗列. React的组件生命周期 r ...
- CEPH Object Gateway
参考文档: CEPH OBJECT GATEWAY:http://docs.ceph.com/docs/master/radosgw/ 一.环境准备 1. Ceph Object Gateway框架 ...
- Nginx反向代理中使用proxy_redirect重定向url
在使用Nginx做反向代理功能时,有时会出现重定向的url不是我们想要的url,这时候就可以使用proxy_redirect进行url重定向设置了.proxy_redirect功能比较强大,其作用是对 ...