結果

問題 No.3076 Goodstuff Deck Builder
ユーザー Hydrogen332
提出日時 2025-03-28 21:50:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 372 ms / 3,000 ms
コード長 1,112 bytes
コンパイル時間 3,518 ms
コンパイル使用メモリ 293,016 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-28 21:50:11
合計ジャッジ時間 9,283 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> C;
    ll sum = 0;
    rep(i, 0, N) {
        ll c, d;
        cin >> c >> d;
        if (c != 0) C.push_back({c, d});
        else sum += d;
    }
    
    sort(C.rbegin(), C.rend());
    N = C.size();
    
    ll ans = 0;
    if (N > 0) {
        vector pre(M + 1, vector<ll>(11, 0));
        vector now(M + 1, vector<ll>(11, 0));
        pre[C[0].first][1] = C[0].second;
        now[C[0].first][1] = C[0].second;
        
        rep(i, 1, N) {
            rep(j, 0, M + 1) rep(t, 0, 10) if (j + (C[i].first << t) <= M) {
                now[j + (C[i].first << t)][t + 1] = max(now[j + (C[i].first << t)][t + 1], pre[j][t] + C[i].second);
            }
            pre = now;
        }
        
        rep(j, 0, M + 1) rep(t, 0, 11) ans = max(ans, now[j][t]);
    }
    
    cout << ans + sum << '\n';
}
0