結果
| 問題 |
No.3076 Goodstuff Deck Builder
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-28 23:31:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 198 ms / 3,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 2,112 ms |
| コンパイル使用メモリ | 205,404 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-28 23:31:06 |
| 合計ジャッジ時間 | 6,289 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll pw2[30];
const ll INF = 1e18;
void chmax(ll &a, ll b) { a = max(a, b); }
void solve() {
pw2[0] = 1;
rep(i, 20) pw2[i + 1] = pw2[i] * 2;
ll n, m;
cin >> n >> m;
vector<pair<ll, ll>> cds(n);
rep(i, n) cin >> cds[i].first >> cds[i].second;
sort(cds.rbegin(), cds.rend());
ll base = 0;
while (!cds.empty() && cds.back().first == 0) {
base += cds.back().second;
cds.pop_back();
}
vector dp(m + 1, vector<ll>(15, -INF));
dp[0][0] = 0;
ll ans = 0;
for (const auto [c, d] : cds) {
for (ll k = 10; k >= 0; k--) {
for (ll j = 0; j < m; j++) {
ll nj = j + c * pw2[k];
if (dp[j][k] >= 0 && nj <= m) {
chmax(dp[nj][k + 1], dp[j][k] + d);
chmax(ans, dp[nj][k + 1]);
}
}
}
}
ans += base;
cout << ans << '\n';
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
int T = 1;
for (int t = 0; t < T; t++) {
solve();
}
return 0;
}