結果
問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
ユーザー |
![]() |
提出日時 | 2025-04-14 16:09:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 232 ms / 3,000 ms |
コード長 | 1,040 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 68,332 KB |
実行使用メモリ | 79,760 KB |
最終ジャッジ日時 | 2025-04-14 16:09:37 |
合計ジャッジ時間 | 5,887 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:42:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 42 | scanf("%d%d", &ci, &di); | ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3077.cc: No.3077 Goodstuff Deck Builder(Hard) - yukicoder */ #include<cstdio> #include<algorithm> #include<functional> #include<utility> using namespace std; /* constant */ const int MAX_N = 10000; const int MAX_M = 10000000; /* typedef */ using ll = long long; using pii = pair<int,int>; /* global variables */ pii ps[MAX_N]; ll dp[MAX_M + 1]; /* subroutines */ void setmax(ll &a, ll b) { if (a < b) a = b; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); ll s0 = 0; int k = 0; for (int i = 0; i < n; i++) { int ci, di; scanf("%d%d", &ci, &di); if (ci == 0) s0 += di; else ps[k++] = {ci, di}; } sort(ps, ps + k, greater<pii>()); n = k; fill(dp, dp + m + 1, -1); dp[m] = 0; int cur = 0, nxt = 1; for (int i = 0; i < n; i++) { auto [ci, di] = ps[i]; for (int j = ci; j <= m; j++) if (dp[j] >= 0) setmax(dp[(j - ci) / 2], dp[j] + di); } ll maxd = *max_element(dp, dp + m + 1); printf("%lld\n", s0 + maxd); return 0; }