Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4500 Accepted Submission(s): 1835
3 1 2 5 -1 5 3 1 2 3 4 5 0 0
5 5 4 3
恶心的题目描述,题意含糊不清。明白真正题意,世界观被刷新了。妈的,总资产为负数的人居然也能叫富翁!!!
用优先队列处理的,很简单,快拍也能做。
代码如下:
#include<cstdio> #include<queue> using namespace std; int main() { int n,m,a; while(scanf("%d%d",&n,&m)&&n||m) { priority_queue<int>q; while(n--) { scanf("%d",&a); q.push(a); } while(m--) { if(q.empty()) break; else if(m==0) printf("%d\n",q.top()); else if(q.size()==1) printf("%d\n",q.top()); else { printf("%d ",q.top()); q.pop(); } } } return 0; }