結果
問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
ユーザー |
|
提出日時 | 2025-03-29 19:59:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 945 ms / 3,000 ms |
コード長 | 1,782 bytes |
コンパイル時間 | 4,338 ms |
コンパイル使用メモリ | 225,972 KB |
実行使用メモリ | 159,448 KB |
最終ジャッジ日時 | 2025-03-29 19:59:27 |
合計ジャッジ時間 | 22,465 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
ソースコード
#include <bits/stdc++.h> #define rep(i, p, n) for (ll i = p; i < (ll)(n); i++) #define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--) using namespace std; using ll = long long; using ld = long double; const double pi = 3.141592653589793; const long long inf = 2 * 1e9; const long long linf = 4 * 1e18; const ll mod1 = 1000000007; const ll mod2 = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // atcoder #include <atcoder/all> using namespace atcoder; using mint1 = modint1000000007; using mint2 = modint998244353; vector<pair<ll, ll>> base = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int main() { ////////////////// ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ////////////////// ll N, M; cin >> N >> M; vector<pair<ll, ll>> li; ll ans = 0; rep(i, 0, N) { ll C, D; cin >> C >> D; if (C == 0) { ans += D; continue; } li.push_back({C, D}); } N = li.size(); sort(li.begin(), li.end()); reverse(li.begin(), li.end()); vector<ll> dp(M+1), ndp(M+1); rep(i, 0, N) { rep(j, 0, M + 1) { chmax(ndp.at(j), dp.at(j)); if (j - li.at(i).first >= 0) { chmax(ndp.at((j - li.at(i).first) / 2), dp.at(j) + li.at(i).second); } } rep(j, 0, M+1) { dp.at(j) = ndp.at(j); ndp.at(j) = 0; } } ll ma = 0; rep(i, 0, M + 1) { chmax(ma, dp.at(i)); } cout << ans + ma; }