結果
問題 |
No.3076 Goodstuff Deck Builder
|
ユーザー |
![]() |
提出日時 | 2025-03-28 22:10:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 295 ms / 3,000 ms |
コード長 | 1,159 bytes |
コンパイル時間 | 3,619 ms |
コンパイル使用メモリ | 292,320 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-28 22:10:20 |
合計ジャッジ時間 | 6,724 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++) #define ll long long ll INF = 4e18; int main() { int N, M; cin >> N >> M; ll p = 0; vector<pair<int, int>> CD; rep(i, 0, N) { int c, d; cin >> c >> d; if (c == 0) p += d; else CD.push_back({c, d}); } N = (int)CD.size(); sort(CD.rbegin(), CD.rend()); vector<unordered_map<int, ll>> dp(29); dp[0][0] = 0; rep(i, 0, N) { for (int j = 27; j >= 0; j--) { for (auto[key, val] : dp[j]) { // cout << i << " " << j << " " << key << " : " << val << endl; //選ぶ ll nkey = key + (1LL<<j) * CD[i].first; if (nkey <= M) { if (dp[j+1].contains(nkey)) { dp[j+1][nkey] = max(dp[j+1][nkey], val + CD[i].second); } else dp[j+1][nkey] = val + CD[i].second; } } } } ll ans = 0; rep(i, 0, 30) { for (auto[key, val] : dp[i]) ans = max(ans, val); } cout << ans+p << endl; }