結果

問題 No.31 悪のミックスジュース
ユーザー mkawa2mkawa2
提出日時 2021-12-10 00:55:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 1,223 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 77,052 KB
最終ジャッジ日時 2023-09-24 17:14:25
合計ジャッジ時間 2,896 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,304 KB
testcase_01 AC 85 ms
76,280 KB
testcase_02 AC 86 ms
76,092 KB
testcase_03 AC 91 ms
77,052 KB
testcase_04 AC 85 ms
76,272 KB
testcase_05 AC 86 ms
76,248 KB
testcase_06 AC 69 ms
71,308 KB
testcase_07 AC 98 ms
76,916 KB
testcase_08 AC 99 ms
76,884 KB
testcase_09 AC 85 ms
76,200 KB
testcase_10 AC 68 ms
71,472 KB
testcase_11 AC 78 ms
76,212 KB
testcase_12 AC 83 ms
76,212 KB
testcase_13 AC 87 ms
76,212 KB
testcase_14 AC 97 ms
76,944 KB
testcase_15 AC 80 ms
76,376 KB
testcase_16 AC 86 ms
76,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 18446744073709551615
# inf = 4294967295
# md = 10**9+7
# md = 998244353

n, V = LI()
cc = LI()
ss = [0]
for c in cc: ss.append(ss[-1]+c)

if V <= n:
    print(ss[-1])
    exit()

ans = ss[-1]
V -= n

mns, mnv = inf, 1
for v, s in enumerate(ss[1:], 1):
    if s*mnv < mns*v: mns, mnv = s, v
# pDB(mns, mnv)

if V > 10000:
    k = (V-10000)//mnv
    V -= mnv*k
    ans += mns*k

dp = [inf]*(V+1)
dp[0] = 0
for i in range(V):
    for v, s in enumerate(ss[1:], 1):
        j = i+v
        if j > V: j = V
        if dp[j] > dp[i]+s: dp[j] = dp[i]+s

print(ans+dp[-1])
0