Ural 1100. Final Standings 桶排序

1100. Final Standings

Time limit: 1.0 second
Memory limit: 16 MB
Old contest software uses bubble sort for generating final standings. But now, there are too many teams and that software works too slow. You are asked to write a program, which generates exactly the same final standings as old software, but fast.

Input

The first line of input contains only integer 1 <  N ≤ 150000 — number of teams. Each of the next  Nlines contains two integers 1 ≤  ID ≤ 10 7 and 0 ≤  M ≤ 100.  ID — unique number of team,  M — number of solved problems.

Output

Output should contain  N lines with two integers  ID and  M on each. Lines should be sorted by  M in descending order using bubble sort (or analog).

Sample

input output
8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4
3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1

Hint

Bubble sort works following way: 
while (exists A[i] and A[i+1] such as A[i] < A[i+1]) do
   Swap(A[i], A[i+1]);
Problem Author: Pavel Atnashev
Problem Source: Tetrahedron Team Contest May 2001 
/**
 *
 * 题目要求要改进冒泡,这就要求排序稳定
 * m是100以内的整数,可以用桶排序
 *
 */

#include <iostream>
#include <cstdio>
using namespace std;
int id[150005],m[150005];
int main()
{
    int i,j,n;
    scanf("%d",&n);
    for(i=0; i<n; i++)
        scanf("%d%d",&id[i],&m[i]);
    for(i=100; i>=0; i--)
        for(j=0; j<n; j++)
            if(m[j]==i)
                printf("%d %d\n",id[j],m[j]);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值