結果
問題 |
No.2701 A cans -> B cans
|
ユーザー |
![]() |
提出日時 | 2024-06-17 17:27:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 1,000 ms |
コード長 | 873 bytes |
コンパイル時間 | 543 ms |
コンパイル使用メモリ | 41,344 KB |
最終ジャッジ日時 | 2025-02-21 23:07:11 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 73 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d%d%d", as + i, bs + i, cs + i); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2701.cc: No.2701 A cans -> B cans - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 5000; const int MAX_M = 5000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], bs[MAX_N], cs[MAX_N]; ll dp0[MAX_N][MAX_M + 1], dp1[MAX_M + 1], dp2[MAX_M + 1]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) scanf("%d%d%d", as + i, bs + i, cs + i); for (int i = 0; i < n; i++) for (int j = as[i]; j <= m; j++) { dp0[i][j] = (ll)bs[i] * cs[i] + dp0[i][j - as[i] + bs[i]]; dp1[j] = max(dp1[j], dp0[i][j]); } for (int j = 1; j <= m; j++) { for (int j1 = 1; j1 <= j; j1++) dp2[j] = max(dp2[j], dp1[j1] + dp2[j - j1]); printf("%lld\n", dp2[j]); } return 0; }