結果

問題 No.156 キャンディー・ボックス
ユーザー kichirb3
提出日時 2018-03-02 00:11:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 550 ms
コンパイル使用メモリ 73,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 16:14:06
合計ジャッジ時間 1,375 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.156 キャンディー・ボックス
// https://yukicoder.me/problems/no/156
//
#include <iostream>
#include <queue>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    priority_queue<int> pq;
    for (auto i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        pq.push(-tmp);
    }

    int ans = 0;
    while (M > 0) {
        if (pq.empty())
            break;
        int candy = pq.top();
        pq.pop();

        M += candy;
        if (M >= 0)
            ++ans;

    }
    cout << ans << endl;
}
0