結果

問題 No.2806 Cornflake Man
ユーザー tanaka255
提出日時 2024-07-12 22:26:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 203,380 KB
最終ジャッジ日時 2025-02-22 04:29:11
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template<typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void solve();
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int t = 1;
  //cin >> t;
  while (t--) {
    solve();
  }
}
int N,M,A[2<<17];
void solve() {
  cin>>N>>M;
  rep(i,N)cin>>A[i];
  sort(A,A+N);
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>>que;
  vector<int>B;
  for(int i=1;i<N;++i){
    if(que.empty()){
      B.emplace_back(A[i]);
      if(2*A[i]<=M)que.push({2*A[i],A[i]});
      continue;
    }
    if(que.top().first<A[i]){
      cout<<-1<<endl;
      return;
    }
    if(que.top().first==A[i]){
      while(!que.empty()&&que.top().first==A[i]){
        auto[a,b]=que.top();
        que.pop();
        a+=b;
        if(a<=M)que.push({a,b});
      }
      continue;
    }
    B.emplace_back(A[i]);
    if(2*A[i]<=M)que.push({2*A[i],A[i]});
  }
  if(!que.empty()){
    cout<<-1<<endl;
    return;
  }
  cout<<B.size()<<endl;
  rep(i,B.size())cout<<B[i]<<" \n"[i+1==(int)B.size()];
}
0