結果

問題 No.2390 Udon Coupon (Hard)
ユーザー shogo314
提出日時 2023-07-21 23:17:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 689 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 80,964 KB
最終ジャッジ日時 2024-09-22 00:47:02
合計ジャッジ時間 8,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 19 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
N = int(input())
AB = [tuple(map(int, input().split())) for i in range(3)]
ans = 0
g = 1
for A, B in AB:
    g = g*A//math.gcd(g, A)
for A, B in AB:
    ans = max(ans, N//g*((g//A)*B))
N %= g
g=AB[1][0]*AB[2][0]//math.gcd(AB[1][0],AB[2][0])
h=max([(g//A)*B for A,B in AB[1:]])
tmp_max=0
for i in range(N+1):
    if AB[0][0]*i>N:
        break
    tmp=AB[0][1]*i
    m=N-AB[0][0]*i
    tmp+=(m//g)*h
    m%=g
    tmp_max_=0
    for j in range(m+1):
        if AB[1][0]*j>m:
            break
        tmp_=AB[1][1]*j
        o=m-j*AB[1][0]
        tmp_+=AB[2][1]*(o//AB[2][0])
        tmp_max_=max(tmp_max_,tmp_)
    tmp+=tmp_max_
    tmp_max=max(tmp,tmp_max)
print(ans+tmp_max)
0