結果

問題 No.3076 Goodstuff Deck Builder
コンテスト
ユーザー zjsdut
提出日時 2026-06-25 12:33:25
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 67 ms / 3,000 ms
コード長 928 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,402 ms
コンパイル使用メモリ 338,992 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-25 12:33:33
合計ジャッジ時間 5,755 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/**
 *    author:  zjs
 *    created: 25.06.2026 11:19:42
**/
#include <bits/stdc++.h>
using namespace std;

const int maxm = 1e3 + 5;
long long f[10][maxm];

struct Card {
    int c, d;
};
bool cmp(Card a, Card b) {
    return a.c > b.c;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long sum = 0;
    vector<Card> a;
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        int c, d;
        cin >> c >> d;
        if (c == 0)
            sum += d;
        else
            a.push_back({c, d});
    }
    sort(a.begin(), a.end(), cmp);
    for (auto [c, d] : a) {
        for (int j = 9; j >= 1; j--) {
            int cost = c << (j - 1);
            for (int k = cost; k <= M; k++)
                f[j][k] = max(f[j][k], f[j - 1][k - cost] + d);
        }
    }
    long long ans = 0;
    for (int j = 0; j <= 9; j++)
        ans = max(ans, f[j][M]);
    cout << ans + sum << '\n';
}
0