結果

問題 No.2390 Udon Coupon (Hard)
ユーザー 👑 MizarMizar
提出日時 2023-07-07 19:40:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 116,736 KB
最終ジャッジ日時 2024-04-15 20:53:53
合計ジャッジ時間 5,293 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,840 KB
testcase_01 AC 45 ms
58,112 KB
testcase_02 AC 47 ms
58,368 KB
testcase_03 AC 50 ms
60,032 KB
testcase_04 AC 46 ms
58,880 KB
testcase_05 AC 49 ms
59,008 KB
testcase_06 AC 41 ms
51,968 KB
testcase_07 AC 44 ms
51,712 KB
testcase_08 AC 41 ms
52,224 KB
testcase_09 AC 106 ms
96,792 KB
testcase_10 AC 47 ms
58,368 KB
testcase_11 AC 44 ms
52,352 KB
testcase_12 AC 42 ms
51,968 KB
testcase_13 AC 46 ms
58,368 KB
testcase_14 AC 46 ms
58,368 KB
testcase_15 AC 42 ms
51,712 KB
testcase_16 AC 43 ms
52,096 KB
testcase_17 AC 45 ms
57,984 KB
testcase_18 AC 46 ms
57,856 KB
testcase_19 AC 47 ms
58,496 KB
testcase_20 AC 41 ms
51,968 KB
testcase_21 AC 41 ms
51,840 KB
testcase_22 AC 46 ms
58,368 KB
testcase_23 AC 49 ms
59,776 KB
testcase_24 AC 74 ms
71,296 KB
testcase_25 AC 76 ms
72,064 KB
testcase_26 AC 76 ms
71,680 KB
testcase_27 AC 74 ms
72,064 KB
testcase_28 AC 75 ms
71,296 KB
testcase_29 AC 117 ms
90,720 KB
testcase_30 AC 107 ms
88,832 KB
testcase_31 AC 116 ms
90,880 KB
testcase_32 AC 124 ms
90,624 KB
testcase_33 AC 119 ms
91,264 KB
testcase_34 AC 181 ms
116,736 KB
testcase_35 AC 173 ms
113,408 KB
testcase_36 AC 171 ms
112,668 KB
testcase_37 AC 175 ms
116,096 KB
testcase_38 AC 179 ms
115,072 KB
testcase_39 AC 75 ms
75,904 KB
testcase_40 AC 75 ms
71,552 KB
testcase_41 AC 72 ms
74,740 KB
testcase_42 AC 65 ms
70,912 KB
testcase_43 AC 73 ms
72,448 KB
testcase_44 AC 51 ms
60,800 KB
testcase_45 AC 58 ms
64,896 KB
testcase_46 AC 50 ms
59,520 KB
testcase_47 AC 48 ms
59,264 KB
testcase_48 AC 59 ms
64,640 KB
testcase_49 AC 42 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
[[a1, b1], [a2, b2], [a3, b3]] = [list(map(int, input().split())) for _ in range(3)]
amin, bmin = min(a1, a2, a3), min(b1, b2, b3)
assert n > 0 and amin > 0 and bmin > 0
if a2 * b1 < a1 * b2:
	a1, b1, a2, b2 = a2, b2, a1, b1
if a3 * b1 < a1 * b3:
	a1, b1, a3, b3 = a3, b3, a1, b1
w = max(n // a1 - a2 - a3, 0)
m = n - w * a1 + 1
p = min(m, max(a1, a2, a3))
dp = [0] * m
r = 0
for i in range(p):
	dp[i] = r = max(
		dp[i - a1] + b1 if i >= a1 else 0,
		dp[i - a2] + b2 if i >= a2 else 0,
		dp[i - a3] + b3 if i >= a3 else 0,
		r,
	)
for i in range(p, m):
	dp[i] = r = max(
		dp[i - a1] + b1,
		dp[i - a2] + b2,
		dp[i - a3] + b3,
		r,
	)
print(r + w * b1)
0