1.题目描述:

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 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
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.

2.题意概述:

给你一个数n,m。代表有n个人,来自m个区域。然后选两个人去比赛,如果超过两个人就输出?

3.解题思路:

用向量维护一下区域,然后特判一下多人情况

4.AC代码:

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define maxn 100100
using namespace std;
vector<pair<int, string> >S[maxn];
bool cmp(pair<int, string> A, pair<int, string> B)
{return A.first > B.first;
}
int main()
{int n, m;scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++){string s; int x, y;cin >> s >> x >> y;S[x].push_back(make_pair(y, s));}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][2].first == S[i][1].first)cout << "?" << endl;else cout << S[i][0].second << " " << S[i][1].second << endl;}}
}

CF - 659B. Qualifying Contest 排序+字符串相关推荐

  1. 【Codeforces】659B Qualifying Contest (sort)

    http://codeforces.com/problemset/problem/659/B n个人,m个地区,选出每个地区分数最高的两个人 下面有n行,每一行的第一个数表示姓名,第二个数是地区的序号 ...

  2. Codeforces 659B Qualifying Contest【模拟,读题】

    写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...

  3. php 升序 排序字符串,PHP asort():对数组排序(升序),并保持索引关系

    PHP asort() 函数用来对数组元素进行升序排序(也就是从低到高排序),并保持索引关系. asort() 是 sort() 的增强版,asort() 除了能保持值和索引的对应关系,其它功能和 s ...

  4. kotlin字符串数组_Kotlin程序读取,遍历,反向和排序字符串数组

    kotlin字符串数组 Given a string array, we have to read, traverse, reverse and sort its elements. 给定一个字符串数 ...

  5. 数组的升序排序 字符串的方法 0308

    使用Arrays类的sort方法排序数组 排序整数数组 import java.util.Arrays; import java.util.Scanner;public class test01 {p ...

  6. 计数排序的应用----排序字符串

    加qq1126137994 微信:liu1126137994 一起学习更多技术!!! 题目: 给你一个原始字符串,根据该字符串内每一个字符串出现的次数,按照ASCII码递增的排序重新调整输出. 举例: ...

  7. Bailian3719 学生信息用qsort排序【排序+字符串库函数】

    3719:学生信息用qsort排序 总时间限制: 1000ms 内存限制: 65536kB 描述 将输入的学生信息按名字排序后输出. 输入 每个学生信息是两行,第一行是名字,由英文字母和空格构成,最长 ...

  8. c语言实现姓名排序———字符串复制函数,字符串比较函数

    函数介绍 1.strcmp(字符数组1,字符数组2或字符常量): 比较两个字符串大小,它是按照ASCII码值的顺序逐个字符地址地,直到出现字符不一样或遇到'\0'为止. 若字符串1>字符串2,函 ...

  9. qsort排序字符串

    qsort排序指针数组(升序) #include<stdio.h> #include<stdlib.h> #include<string.h>int cmp(con ...

  10. Dwarves(拓扑排序+字符串使用map量化表示)

    题目描述 Once upon a time, there arose a huge discussion among the dwarves in Dwarfland. The government w ...

最新文章

  1. 数字化探索:建立学习型组织,HR 也能驱动业务营收?
  2. 微软小冰从上海音乐学院音工系毕业,师从于阳、陈世哲
  3. 推荐:介绍一个UndoFramework
  4. Java报异常时getMessage()方法返回null
  5. MySQL学习(四)查询
  6. java nginx tomcat_Nginx + Tomcat (java )服务器部署
  7. 2017蓝桥杯:承压计算
  8. 再见了微服务!全面拥抱 DDD 真正的价值
  9. 数据科学家数据分析师_站出来! 分析人员,数据科学家和其他所有人的领导和沟通技巧...
  10. python mvc_python mvc设计模式(一)
  11. OpenShift 4 之Knative(3) - 通过事件触发Serverless服务
  12. 阿里巴巴早期发展简史
  13. 解读联想重组:终于裁员了
  14. [POJ3537]Crosses and Crosses
  15. 七大江河水系--长江(二)
  16. Entry name ‘classes.dex‘ collided
  17. 【python】字符串string的截取;获取字符串内的一串
  18. linux u盘显示只读文件,解决linux下U盘文件只读的问题
  19. Oracle怎么查hex值,oracle 进制转换 HEX/DECIMAL/OCTAL/BINARY
  20. ps基础学习:钢笔工具抠图

热门文章

  1. Win10插入U盘无反应,但是U盘是正常的解决方法
  2. win10系统如何启动sql服务器,win10系统打开SQL Server数据库服务的方法
  3. SpringMVC快速上手教程及SSM整合案例
  4. 塔勒布《反脆弱》读后感
  5. for循环遍历Set集合时如何判断是否有下一个元素
  6. win10 电脑桌面任务栏点击无反应
  7. 南京有哪些不错的互联网公司
  8. 如何使用JavaScript重定向到其他网页?
  9. 【谷歌浏览器】国内如何配置谷歌浏览器使用
  10. python安装包时报错Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools