結果
問題 | No.3076 Goodstuff Deck Builder |
ユーザー |
![]() |
提出日時 | 2025-03-28 22:42:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 253 ms / 3,000 ms |
コード長 | 1,479 bytes |
コンパイル時間 | 3,842 ms |
コンパイル使用メモリ | 290,768 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-28 22:42:13 |
合計ジャッジ時間 | 8,750 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> //#include <atcoder/modint> using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* コストが低いものを先に使っているなら、入れ替えることで総コストは増えない。 コストが0のものは後でまとめて使うとして良い。 10枚使えば、コストは1000を超える。 dp(i, j, k) = i枚目まででj枚使って、エネルギーをk消費する時の最大値 */ ll N, M, ans=0, c, d; cin >> N >> M; vector<pair<ll, ll>> v; for (int i=0; i<N; i++){ cin >> c >> d; if (c == 0) ans += d; else v.push_back({c, d}); } sort(v.rbegin(), v.rend()); vector<ll> pw(11); pw[0] = 1; for (int i=1; i<=10; i++) pw[i] = pw[i-1] * 2; vector dp(11, vector<ll>(M+1)); for (auto [c, d] : v){ vector pd(11, vector<ll>(M+1)); for (int i=0; i<=10; i++){ for (int j=0; j<=M; j++){ pd[i][j] = max(pd[i][j], dp[i][j]); ll cost = c * pw[i]; if (i+1<=10 && j+cost <= M) pd[i+1][j+cost] = max(pd[i+1][j+cost], dp[i][j]+d); } } swap(dp, pd); } ll mx=0; for (int i=0; i<=10; i++){ for (int j=0; j<=M; j++) mx = max(mx, dp[i][j]); } cout << mx+ans << endl; return 0; }