sort

sort

Time Limit : 6000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 139   Accepted Submission(s) : 39

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

给你n个整数,请按从大到小的顺序输出其中前m大的数。

Input

每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。

Output

对每组测试数据按从大到小的顺序输出前m大的数。

Sample Input

5 3
3 -35 92 213 -644

Sample Output

213 92 3

Hint

Hint
请用VC/VC++提交

Author

LL

Source

ACM暑期集训队练习赛(三)
这题明显要用优先队列

#include<iostream>
#include<queue>
using namespace std;
int main()
{
 int n,m;
 while(scanf("%d %d",&n,&m)!=EOF)
 {
  priority_queue<int> q;
  int i=0;
  while(i++<n)
  {
   int u;
   scanf("%d",&u);
   q.push(u);
  }
  i=0;
  while(i++<m)
  {
   int w;
   w=q.top();
   q.pop();
   if(i==1)
    printf("%d",w);
   else
    printf(" %d",w);
  
  }
  printf("\n");
  


 }

 

 


}

 
posted @ 2013-08-15 11:37  一只蚊子  阅读(137)  评论(0编辑  收藏  举报