题目连接

http://codeforces.com/contest/659/problem/B

Description

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.

Sample Input

5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503

Sample Output

Sidorov Ivanov
Andreev Semenov

Hint

题意

找出区域内,分数最高的两个人,排序之后比较一下第二和第三的分数,因为第一 一定是可以出线的(即使第二的分数和他一样),要比较第二和第三来决定是否需要加赛。

代码

#include<bits/stdc++.h>
using namespace std;
#define maxn 1000
#define INF  1e9+7
#define ll long long
#define eps 1e-6
typedef pair<int , string> p; //注意string和int的先后
bool cmp(p pa,p pb){return pa.first>pb.first;
}
vector< p > s[10005];
int main(int argc, char const *argv[])
{int n,m;cin>>n>>m;for (int i = 0; i < n; ++i){string q;int a,b;cin>>q>>a>>b;p pa=make_pair(b,q);s[a].push_back(pa);}for (int i = 1; i<=m; ++i){sort(s[i].begin(),s[i].end(),cmp);}for (int i = 1; i<=m ; ++i){if (s[i].size()==2){cout<<s[i][0].second<<' '<<s[i][1].second<<endl;}else{if (s[i][1].first==s[i][2].first){cout<<'?'<<endl;}else{cout<<s[i][0].second<<' '<<s[i][1].second<<endl;}}}return 0;
}

Get

重点是vector与Pair结合处理数据的方式,以及sort与bool的排序
表格

CF 346 B vectorpair s[100]相关推荐

  1. 吉尼斯战斗之夜——记第一次包夜开黑cf

    12点半我们宿舍集合,四个人开黑打cf.本来应该上100多分的,现在只剩下了一个零头,让我怎么不生气.本来还想看日出了,一起玩玩魔兽就没去..单机版的魔兽.开始的一个题,超级简单5分钟轻松水过.第二题 ...

  2. plsa java_PLSA

    PLSA模型 PLSA和LDA很像,都属于主题模型,即它们都认为上帝在写文章时先以一定概率选择了一个主题,然后在这主题下以一定概率选择了一个词,重复这个过程就完成了一篇文章,即$p(d_i,w_j)= ...

  3. c语言找出比n小的最大质数,C++ 实现求小于n的最大素数的实例

    C++ 实现求小于n的最大素数的实例 枚举就是基于已有知识镜像答案猜测的一种问题求解策略 问题:求小于n的最大素数 分析: 找不到一个数学公式,使得根据N就可以计算出这个素数 我们思考: N-1是素数 ...

  4. 求素数的方法完整归纳,学的不仅是“求素数”!

    一.相关概念 定义:素数(Prime Number)又称质数,是指大于1且只能被1和它本身整除的正整数,例如2,3,5,7,11等. 与素数相对的就是合数,它能被一个本身之外的数整除,例如4,6,8, ...

  5. Hive集成HBase详解

    摘要 Hive提供了与HBase的集成,使得能够在HBase表上使用HQL语句进行查询 插入操作以及进行Join和Union等复杂查询 应用场景 1. 将ETL操作的数据存入HBase 2. HBas ...

  6. 绝对好文:嵌入式系统的软件架构设计!

    要学嵌入式,关注@我要学嵌入式,嵌入式猛男的加油站. 1. 前言 嵌入式是软件设计领域的一个分支,它自身的诸多特点决定了系统架构师的选择,同时它的一些问题又具有相当的通用性,可以推广到其他的领域. 提 ...

  7. 轻量级持久存储系统 MemcacheDB

    轻量级持久存储系统 MemcacheDB(转载) (2010-10-18 13:18:07) 转载▼ 标签: 代码 复制 默认 守护进程 主从 it   注:memcached可能简称mc,memca ...

  8. python3 tkinter 实现凯撒密码GUI界面

    Codes import tkinter as tk from tkinter import messageboxclass Kaisa():def __init__(self): # 构造函数sel ...

  9. MySQL求n以内素数_C++ 实现求小于n的最大素数的实例

    C++ 实现求小于n的最大素数的实例 枚举就是基于已有知识镜像答案猜测的一种问题求解策略 问题:求小于n的最大素数 分析: 找不到一个数学公式,使得根据N就可以计算出这个素数 我们思考: N-1是素数 ...

  10. 无线网卡芯片类型及与linux-wlan-ng的兼容性

    无线局域网适配器芯片集由 AbsoluteValue Systems, Inc.提供,更新至2004年2月           LINUX SUPPORT   VENDOR WLAN TYPE PRO ...

最新文章

  1. java实现简单的二叉树ADT
  2. JavaScript学习笔记(七)——厚积薄发之小成果
  3. Python安装第三方库太慢?配置好这个速度飞起
  4. 单词九连猜python编程_python实现猜单词游戏
  5. 八、VueJs 填坑日记之参数传递及内容页面的开发
  6. 实例3 如何使用菜单控件
  7. sql用户名数据迁移到mysql_如何将SQL Server数据迁移到MySQL
  8. LVM与软RAID整理笔记
  9. 结合工作经历推荐新手编程语言
  10. 噇字符集linux,gbk编码
  11. 回溯法之迷宫问题(华为笔试题)
  12. 【FPGA——协议篇】:I2C总线协议详解+verilog源码
  13. 微信模拟器不显示鼠标解决办法
  14. 前馈控制与反馈控制对比
  15. 笔记1-fedora14初识及vmware-tool安装
  16. 盘点一下文明与征服几个主流阵容搭配
  17. appium+python闲鱼采购自动化测试实战
  18. 计算机类软件工程与测绘类遥感专业的薪水,2018遥感科学与技术专业就业前景和就业方向分析...
  19. python实现word文档合并
  20. 沈航数值统计-16-17A+B

热门文章

  1. Typora 官网下载
  2. windows客户端,坚果云如何开启云桥模式
  3. Oracle如何对JDK收费
  4. 海康摄像头车牌识别和顶拍同步抓拍图片
  5. Oracle ERP 模块
  6. java命令行打包war_手工命令行打包java工程为war包
  7. 001云E办项目之创建项目
  8. 图文详解超五类网线的接法
  9. php微信公众号绑定微信号,订阅号实现微信网页授权登陆(原创)
  10. 青果教务管理系统存储型XSS 一枚