結果

問題 No.2806 Cornflake Man
ユーザー GOTKAKOGOTKAKO
提出日時 2024-07-12 21:40:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 211,600 KB
実行使用メモリ 7,412 KB
最終ジャッジ日時 2024-07-17 20:26:16
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
6,816 KB
testcase_01 AC 38 ms
6,944 KB
testcase_02 AC 7 ms
6,944 KB
testcase_03 AC 39 ms
6,940 KB
testcase_04 AC 7 ms
6,940 KB
testcase_05 AC 9 ms
6,940 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 48 ms
6,940 KB
testcase_08 AC 14 ms
6,940 KB
testcase_09 AC 25 ms
6,944 KB
testcase_10 AC 18 ms
6,940 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 22 ms
6,940 KB
testcase_13 AC 43 ms
6,940 KB
testcase_14 AC 9 ms
6,940 KB
testcase_15 AC 51 ms
7,412 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    sort(A.begin(),A.end());

    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> Q;
    bool ok = true;
    vector<int> B;
    for(int i=1; i<N; i++){
        int a = A.at(i);
        bool already = false;
        while(Q.size()){
            auto [t,add] = Q.top();
            if(t > a) break;
            else if(t < a){ok = false; break;}
            Q.pop(); Q.push({t+add,add});
            already = true;
        }
        if(!ok) break;
        if(!already) Q.push({a+a,a}),B.push_back(a);
    }
    if(Q.top().first <= M || !ok) cout << "-1" << endl;
    else if(ok){
        cout << B.size() << endl;
        for(auto &b : B) cout << b << " "; cout << endl;
    }
    else cout << -1 << endl;
}
0