Codeforces - 1088B - Ehab and subtraction - 堆

https://codeforc.es/contest/1088/problem/B

模拟即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

priority_queue<int, vector<int>, greater<int> >pq;
int sumsub = 0;

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
    //freopen("Yinku.out", "w", stdout);
#endif // Yinku
    int n, k;
    while(~scanf("%d%d", &n, &k)) {
        while(!pq.empty())
            pq.pop();
        for(int i = 1; i <= n; i++) {
            int tmp;
            scanf("%d", &tmp);
            pq.push(tmp);
        }
        sumsub = 0;
        for(int i = 1; i <= k; i++) {
            int tmp = 0;
            while(!tmp) {
                if(pq.empty())
                    break;
                tmp = pq.top() - sumsub;
                pq.pop();
            }
            printf("%d\n", tmp);
            sumsub += tmp;
        }
    }
}
posted @ 2019-07-17 13:13  韵意  阅读(213)  评论(0编辑  收藏  举报