結果

問題 No.595 登山
ユーザー pluto77pluto77
提出日時 2018-01-04 15:22:31
言語 Python2
(2.7.18)
結果
AC  
実行時間 768 ms / 1,500 ms
コード長 418 bytes
コンパイル時間 1,276 ms
コンパイル使用メモリ 6,576 KB
実行使用メモリ 50,168 KB
最終ジャッジ日時 2023-08-24 18:54:55
合計ジャッジ時間 18,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
32,580 KB
testcase_01 AC 151 ms
32,580 KB
testcase_02 AC 148 ms
32,568 KB
testcase_03 AC 151 ms
32,680 KB
testcase_04 AC 733 ms
49,292 KB
testcase_05 AC 315 ms
37,440 KB
testcase_06 AC 646 ms
46,988 KB
testcase_07 AC 200 ms
34,088 KB
testcase_08 AC 239 ms
34,780 KB
testcase_09 AC 655 ms
47,068 KB
testcase_10 AC 503 ms
42,596 KB
testcase_11 AC 469 ms
41,392 KB
testcase_12 AC 197 ms
33,676 KB
testcase_13 AC 304 ms
36,952 KB
testcase_14 AC 748 ms
44,472 KB
testcase_15 AC 746 ms
44,472 KB
testcase_16 AC 748 ms
44,376 KB
testcase_17 AC 744 ms
44,300 KB
testcase_18 AC 755 ms
44,376 KB
testcase_19 AC 760 ms
50,148 KB
testcase_20 AC 768 ms
50,120 KB
testcase_21 AC 761 ms
50,064 KB
testcase_22 AC 760 ms
50,056 KB
testcase_23 AC 762 ms
50,068 KB
testcase_24 AC 151 ms
32,680 KB
testcase_25 AC 150 ms
32,676 KB
testcase_26 AC 763 ms
50,168 KB
testcase_27 AC 749 ms
46,204 KB
testcase_28 AC 745 ms
46,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki_595

INF=float('inf')
dp=[[INF for i in xrange(2)] for j in xrange(200000)]
n,p=map(int,raw_input().split())
h=map(int,raw_input().split())
dp[0][0]=0
for i in xrange(n-1):
 dp[i+1][0]=min(dp[i+1][0],dp[i][0]+min(p,max(h[i+1]-h[i],0)))
 dp[i+1][1]=min((dp[i+1][1],dp[i][0]+p))
 dp[i+1][1]=min(dp[i+1][1],dp[i][1]+min(p,max(h[i]-h[i+1],0)))
 dp[i+1][0]=min(dp[i+1][0],dp[i][1]+p)
print min(dp[n-1][0],dp[n-1][1])
0