結果
問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
ユーザー |
![]() |
提出日時 | 2025-03-29 00:38:03 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 957 ms / 3,000 ms |
コード長 | 1,084 bytes |
コンパイル時間 | 3,202 ms |
コンパイル使用メモリ | 286,964 KB |
実行使用メモリ | 159,380 KB |
最終ジャッジ日時 | 2025-03-29 00:38:24 |
合計ジャッジ時間 | 20,099 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#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); /* コストを半分にする代わりに残りのエネルギーを半分にする。 すると、枚数を状態にもつ必要がない。 dp(i) = 残りエネルギーがjのときの最大値 dp((i-C)/2) <- dp(i)+D */ 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> dp(M+1); for (auto [c, d] : v){ vector<ll> pd(M+1); for (int j=0; j<=M; j++){ pd[j] = max(pd[j], dp[j]); if (j >= c) pd[(j-c)/2] = max(pd[(j-c)/2], dp[j]+d); } swap(dp, pd); } ll mx=0; for (int i=0; i<=M; i++) mx = max(mx, dp[i]); cout << mx+ans << endl; return 0; }