結果

問題 No.1037 exhausted
ユーザー ayaoniayaoni
提出日時 2020-12-14 04:48:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 1,118 bytes
コンパイル時間 563 ms
コンパイル使用メモリ 81,480 KB
実行使用メモリ 108,112 KB
最終ジャッジ日時 2023-10-20 04:41:25
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,340 KB
testcase_01 AC 40 ms
53,340 KB
testcase_02 AC 39 ms
53,340 KB
testcase_03 AC 39 ms
53,340 KB
testcase_04 AC 40 ms
53,340 KB
testcase_05 AC 40 ms
53,340 KB
testcase_06 AC 40 ms
53,340 KB
testcase_07 AC 40 ms
53,340 KB
testcase_08 AC 39 ms
53,340 KB
testcase_09 AC 40 ms
53,340 KB
testcase_10 AC 40 ms
53,340 KB
testcase_11 AC 40 ms
53,340 KB
testcase_12 AC 182 ms
107,516 KB
testcase_13 AC 182 ms
107,484 KB
testcase_14 AC 179 ms
107,384 KB
testcase_15 AC 179 ms
107,488 KB
testcase_16 AC 182 ms
107,360 KB
testcase_17 AC 194 ms
108,112 KB
testcase_18 AC 179 ms
107,464 KB
testcase_19 AC 182 ms
107,464 KB
testcase_20 AC 251 ms
108,108 KB
testcase_21 AC 170 ms
107,416 KB
testcase_22 AC 133 ms
107,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,V,L = MI()
XVW = [(0,0,0)]+[tuple(MI()) for _ in range(N)]
XVW.sort()

inf = 10**18
dp = [[inf]*(V+1) for _ in range(N+1)]
# dp[i][j] = i番目の地点に到達した際に、j以上の燃料を残すために必要な費用の最小値

for j in range(V+1):
    dp[0][j] = 0

for i in range(1,N+1):
    x,v,w = XVW[i]
    d = x-XVW[i-1][0]
    for j in range(V+1):
        if j+d <= V:
            dp[i][j] = min(dp[i][j],dp[i-1][j+d])
        if max(j-v,0)+d <= V:
            dp[i][j] = min(dp[i][j],dp[i-1][max(j-v,0)+d]+w)

y = L-XVW[-1][0]

if y > V:
    print(-1)
else:
    ans = dp[-1][y]
    if ans >= inf:
        print(-1)
    else:
        print(ans)
0