結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,492 KB
testcase_01 AC 41 ms
53,492 KB
testcase_02 AC 39 ms
53,492 KB
testcase_03 AC 39 ms
53,492 KB
testcase_04 AC 38 ms
53,492 KB
testcase_05 AC 39 ms
53,492 KB
testcase_06 AC 39 ms
53,492 KB
testcase_07 AC 39 ms
53,492 KB
testcase_08 AC 38 ms
53,492 KB
testcase_09 AC 41 ms
53,492 KB
testcase_10 AC 38 ms
53,492 KB
testcase_11 AC 39 ms
53,492 KB
testcase_12 AC 182 ms
107,592 KB
testcase_13 AC 181 ms
107,604 KB
testcase_14 AC 179 ms
107,508 KB
testcase_15 AC 179 ms
107,608 KB
testcase_16 AC 181 ms
107,484 KB
testcase_17 AC 189 ms
108,236 KB
testcase_18 AC 178 ms
107,588 KB
testcase_19 AC 181 ms
107,588 KB
testcase_20 AC 249 ms
108,236 KB
testcase_21 AC 169 ms
107,540 KB
testcase_22 AC 131 ms
107,888 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