結果

問題 No.31 悪のミックスジュース
ユーザー cologne
提出日時 2022-01-23 14:25:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,058 ms / 5,000 ms
コード長 709 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 82,536 KB
実行使用メモリ 107,900 KB
最終ジャッジ日時 2024-11-29 14:22:20
合計ジャッジ時間 9,618 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
import sys
import fractions

input = sys.stdin.readline


def main():
    N, V = map(int, input().split())
    *C, = itertools.accumulate(map(int, input().split()))

    V -= N
    if V <= 0:
        print(C[-1])
        return

    L = (N**3-N)//2
    DP = [0] + [float('inf')]*L

    for i in range(1, L+1):
        for j in range(N):
            if i > j:
                DP[i] = min(DP[i], DP[i-(j+1)]+C[j])

    if V <= L:
        print(C[-1] + DP[V])
    else:
        target = min(range(N), key=lambda i: fractions.Fraction(C[i], i+1))
        greedy = (V-(L+1))//(target+1) + 1
        print(C[-1] + greedy*C[target] + DP[V-(target+1)*greedy])


if __name__ == '__main__':
    main()
0