結果

問題 No.3076 Goodstuff Deck Builder
ユーザー GOTKAKO
提出日時 2025-03-28 21:16:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 281 ms / 3,000 ms
コード長 914 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 206,484 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2025-03-28 21:16:25
合計ジャッジ時間 6,046 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    long long N,M; cin >> N >> M;
    vector<pair<long long,long long>> CD(N);
    for(auto &[c,d] : CD) cin >> c >> d;
    sort(CD.rbegin(),CD.rend());
    long long add = 0;
    while(CD.size()){
        auto [c,d] = CD.back();
        if(c == 0) add += d,CD.pop_back();
        else break;
    }

    long long inf = 1e18;
    vector dp(11,vector(M+1,-inf));
    dp.at(0).at(0) = 0;
    for(auto [c,d] : CD){
        c <<= 9;
        for(long long i=9; i>=0; i--,c>>=1) for(long long k=0; ; k++){
            if(k+c > M) break;
            if(dp.at(i).at(k) == inf) continue;
            dp.at(i+1).at(k+c) = max(dp.at(i+1).at(k+c),dp.at(i).at(k)+d);
        }
    }

    long long answer = add;
    for(auto &d : dp) for(auto v : d) answer = max(answer,v+add);
    cout << answer << endl;
}
0