結果

問題 No.2390 Udon Coupon (Hard)
ユーザー mymelochanmymelochan
提出日時 2023-07-21 23:19:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,330 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 146,304 KB
最終ジャッジ日時 2024-04-15 21:04:55
合計ジャッジ時間 8,526 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
62,592 KB
testcase_01 AC 55 ms
64,384 KB
testcase_02 AC 161 ms
146,176 KB
testcase_03 AC 241 ms
146,116 KB
testcase_04 AC 204 ms
146,148 KB
testcase_05 AC 53 ms
62,372 KB
testcase_06 AC 143 ms
131,840 KB
testcase_07 AC 45 ms
54,400 KB
testcase_08 AC 46 ms
54,656 KB
testcase_09 AC 207 ms
135,168 KB
testcase_10 AC 54 ms
62,592 KB
testcase_11 AC 55 ms
63,232 KB
testcase_12 AC 53 ms
61,952 KB
testcase_13 AC 53 ms
62,720 KB
testcase_14 AC 55 ms
63,744 KB
testcase_15 AC 57 ms
63,872 KB
testcase_16 AC 55 ms
63,616 KB
testcase_17 AC 54 ms
62,464 KB
testcase_18 AC 54 ms
63,360 KB
testcase_19 AC 54 ms
62,976 KB
testcase_20 AC 45 ms
54,656 KB
testcase_21 AC 46 ms
54,912 KB
testcase_22 AC 154 ms
134,016 KB
testcase_23 AC 148 ms
132,352 KB
testcase_24 AC 190 ms
134,656 KB
testcase_25 AC 189 ms
134,528 KB
testcase_26 AC 191 ms
136,064 KB
testcase_27 AC 190 ms
134,656 KB
testcase_28 AC 192 ms
140,032 KB
testcase_29 AC 203 ms
135,936 KB
testcase_30 AC 222 ms
146,304 KB
testcase_31 AC 206 ms
137,728 KB
testcase_32 AC 204 ms
136,448 KB
testcase_33 AC 223 ms
146,244 KB
testcase_34 AC 205 ms
136,320 KB
testcase_35 AC 210 ms
135,680 KB
testcase_36 AC 203 ms
136,576 KB
testcase_37 AC 208 ms
137,472 KB
testcase_38 AC 215 ms
146,172 KB
testcase_39 AC 110 ms
93,440 KB
testcase_40 AC 158 ms
133,888 KB
testcase_41 AC 209 ms
134,528 KB
testcase_42 AC 187 ms
132,968 KB
testcase_43 AC 204 ms
135,296 KB
testcase_44 AC 177 ms
134,528 KB
testcase_45 AC 179 ms
135,040 KB
testcase_46 AC 153 ms
141,312 KB
testcase_47 AC 174 ms
135,936 KB
testcase_48 AC 183 ms
133,504 KB
testcase_49 AC 47 ms
54,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#############################################################

import sys
sys.setrecursionlimit(10**7)

from heapq import heappop,heappush
from collections import deque,defaultdict,Counter
from bisect import bisect_left, bisect_right
from itertools import product,combinations,permutations

ipt = sys.stdin.readline

def iin():
    return int(ipt())
def lmin():
    return list(map(int,ipt().split()))

MOD = 998244353
inf = 1<<60
#############################################################

M = 3000**2

N = iin()
A1,B1 = lmin()
A2,B2 = lmin()
A3,B3 = lmin()

if N < M:
    dp = [-inf]*(N+1)
    dp[0] = 0
    for i in range(1,N+1):
        if i >= A1:
            dp[i] = max(dp[i],dp[i-A1]+B1)
        if i >= A2:
            dp[i] = max(dp[i],dp[i-A2]+B2)
        if i >= A3:
            dp[i] = max(dp[i],dp[i-A3]+B3)
    print(max(dp))
else:
    L = N-M
    r = (L+A1-1)//A1
    t = r*A1
    
    dp = [-inf]*(M+1)
    dp[t-L] = max(dp[t-L],B1*r)

    r = (L+A2-1)//A2
    t = r*A2
    
    dp[t-L] = max(dp[t-L],B2*r)

    r = (L+A3-1)//A3
    t = r*A3

    dp[t-L] = max(dp[t-L],B3*r)

    for i in range(1,M+1):
        if i >= A1:
            dp[i] = max(dp[i],dp[i-A1]+B1)
        if i >= A2:
            dp[i] = max(dp[i],dp[i-A2]+B2)
        if i >= A3:
            dp[i] = max(dp[i],dp[i-A3]+B3)
    print(max(dp))
0