結果
| 問題 |
No.2806 Cornflake Man
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-12 21:40:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 922 bytes |
| コンパイル時間 | 2,284 ms |
| コンパイル使用メモリ | 205,692 KB |
| 最終ジャッジ日時 | 2025-02-22 03:42:14 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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;
}