这题用了点小小的技巧,用cnt记录应该减去的数的和,实际上并没有真正的进行减法运算
http://codeforces.com/contest/1088/problem/B
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define ll long long
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
priority_queue<int, vector<int>, greater<int> >q;
int n, k;
scanf("%d%d",&n,&k);
for(int i = 1; i <= n; i ++)
{
int tmp;
scanf("%d",&tmp);
if(tmp)
q.push(tmp);
}
int cnt = 0;
while(k --)
{
if(!q.empty()){
int h = q.top();
if(h - cnt == 0)
{
k ++;
q.pop();
continue;
}
q.pop();
cout<<h - cnt<<endl;
cnt += (h-cnt);
}
else
{
cout<<0<<endl;
}
}
return 0;
}