結果

問題 No.31 悪のミックスジュース
ユーザー Mao-betaMao-beta
提出日時 2024-02-29 18:09:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,688 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,044 KB
最終ジャッジ日時 2024-02-29 18:09:27
合計ジャッジ時間 2,642 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 115 ms
76,020 KB
testcase_05 AC 88 ms
76,020 KB
testcase_06 AC 45 ms
55,744 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 46 ms
57,828 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 46 ms
57,832 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N, V = NMI()
    C = NLI()
    X = list(accumulate(C))
    Y = list(range(1, N+1))
    ans = X[-1]
    V -= Y[-1]

    if V <= 0:
        print(ans)
        return

    XY = [[x, y] for x, y in zip(X, Y)]

    from functools import cmp_to_key

    def cmp(a, b):
        ax, ay = a
        bx, by = b
        if ax * by < bx * ay:
            return -1
        elif ax * by > bx * ay:
            return 1
        else:
            if bx > by:
                return -1
            elif bx < by:
                return 1
            else:
                return 0

    XY = sorted(XY, key=cmp_to_key(cmp))
    x, y = XY[-1]
    if V > N**2:
        k = (V - N**2) // y
        ans += k * x
        V -= k * y

    # i個見て量j(<=N**2)あるときの値段の最小値
    INF = 10**20
    dp = [INF]*(V+1)
    dp[0] = 0
    for i in range(N):
        x, y = XY[i]
        for j in range(V+1):
            if dp[j] >= INF:
                continue
            nj = j + y
            nj = min(nj, V)
            dp[nj] = min(dp[nj], dp[j] + x)

    print(ans + dp[V])


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