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的更多相关文章
随机推荐
- 网络流量状态命令总结 (含notp安装)
1. sar -n DEV 1 2 sar命令包含在sysstat工具包中,提供系统的众多统计数据.其在不同的系统上命令有些差异,某些系统提供的sar支持基于网络接口的数据统计,也可以查看设备上每秒收 ...
- C语言程序设计II—第六周教学
第六周教学总结(1/4-7/4) 教学内容 本周的教学内容为:第八章 指针 8.1 密码开锁(知识点:指针和指针变量的概念),8.2 角色互换(知识点:指针作为函数的参数返回多个值) 重点.难点:指针 ...
- JQuery加载html网页
在ASP.NET MVC环境中,使用jQuery脚本去实现加载html网页. 一般情况之下,在ASP.NET MVC项目中,你不能在~/Views目录之下添加或是创建任何html为后缀的网页.但这也不 ...
- linux shell的here document用法
转载自: http://my.oschina.net/u/1032146/blog/146941 什么是Here Document?Here Document 是在Linux Shell 中的一种特殊 ...
- POJ1845
这还是一道综合了许多数论的知识点的,做完也涨了不少姿势 但还是因为约数和公式这个鬼东西去找了度娘 题意很简单,就是求\(A^B\)的约数之和\(mod\ 9901\). 但是这种题意越是简单的题目越是 ...
- asp.net core使用jexus部署在linux无法正确 获取远程ip的解决办法
asp.net core程序部署在centos7(下面的解决方案,其他系统都能使用,这里只是我自己部署在centos7),使用服务器jexus进行部署,AppHost模式. 因为请求是由jexus进行 ...
- 事务,acid,cap,paxos随笔
事务ACID四个特性: A:原子性(Atomicity)C:一致性(Consistency)I:隔离性(Isolation)D:持久性(Durability) 原子性:语句要么全执行,要么全不执行,是 ...
- WPF没落了吗?
从08年开始一直到现在,碰到所有的项目,我个人经手的,都用wpf开发. wpf应该说一直没有火过,一直平平淡淡. 个人为什么一直执着用wpf,开始使用是因公司项目,做了两年wpf开发,后来换工作一直搜 ...
- U盘、移动硬盘等弹出 “文件或目录损坏且无法读取” 实测解决办法
U盘跟其他的机器一样,使用久了难免会出故障,比如常见的弹出一个文件或目录损坏且无法读取的对话框,吓你一跳,整个U盘都损坏的意思,那里面的资料怎么办呢,所以很多人很着急,其实遇到这种情况一般都是之前使用 ...
- win10系统安装web3js的正确方法(2)
信渤网络科技是一家基于互联网信息服务的区块链技术公司,专业提供区块链技术培训,智能合约定制开发,文字图片数据存证上链等服务,为相关企业提供区块链应用落地项目的技术方案 崇尚代码即法律,做一个智能合约开 ...