結果
問題 | No.2701 A cans -> B cans |
ユーザー |
![]() |
提出日時 | 2024-05-11 13:39:38 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 697 ms / 1,000 ms |
コード長 | 865 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 30,080 KB |
実行使用メモリ | 197,432 KB |
最終ジャッジ日時 | 2024-12-20 08:28:51 |
合計ジャッジ時間 | 28,439 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 73 |
ソースコード
#include <stdio.h>int main () {int n = 0;int m = 0;int a[5000] = {};int b[5000] = {};long long c[5000] = {};int res = 0;long long dp[5001][5000] = {};res = scanf("%d", &n);res = scanf("%d", &m);for (int i = 0; i < n; i++) {res = scanf("%d", a+i);res = scanf("%d", b+i);res = scanf("%lld", c+i);}for (int i = 0; i < m; i++) {long long ans = 0LL;for (int j = 0; j < n; j++) {if (i+1 >= a[j] && ans < dp[i+1-a[j]][j]+((long long)b[j])*c[j]) {ans = dp[i+1-a[j]][j]+((long long)b[j])*c[j];}}for (int j = 0; j < n; j++) {dp[i+1][j] = ans;if (i+1 >= a[j]-b[j] && dp[i+1][j] < dp[i+1-a[j]+b[j]][j]+((long long)b[j])*c[j]) {dp[i+1][j] = dp[i+1-a[j]+b[j]][j]+((long long)b[j])*c[j];}}printf("%lld\n", ans);}return 0;}