結果
問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
ユーザー |
![]() |
提出日時 | 2025-03-29 00:28:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,114 bytes |
コンパイル時間 | 3,955 ms |
コンパイル使用メモリ | 290,352 KB |
実行使用メモリ | 814,028 KB |
最終ジャッジ日時 | 2025-03-29 00:28:27 |
合計ジャッジ時間 | 6,077 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | MLE * 1 -- * 56 |
ソースコード
#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); 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(24); pw[0] = 1; for (int i=1; i<=23; i++) pw[i] = pw[i-1] * 2; vector dp(24, vector<ll>(M+1)); for (auto [c, d] : v){ vector pd(24, vector<ll>(M+1)); for (int i=0; i<=23; 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<=23 && 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<=23; i++){ for (int j=0; j<=M; j++) mx = max(mx, dp[i][j]); } cout << mx+ans << endl; return 0; }