結果
| 問題 |
No.595 登山
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:38:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 634 bytes |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 82,340 KB |
| 実行使用メモリ | 119,932 KB |
| 最終ジャッジ日時 | 2025-06-12 21:42:19 |
| 合計ジャッジ時間 | 3,972 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 20 |
ソースコード
def main():
import sys
input = sys.stdin.read().split()
idx = 0
N = int(input[idx])
idx += 1
P = int(input[idx])
idx += 1
H = list(map(int, input[idx:idx+N]))
if N == 1:
print(0)
return
total_cost = 0
start = 0
while start < N-1:
end = start
while end < N-1 and H[end+1] >= H[end]:
end += 1
# 区间是 start 到 end
D = H[end] - H[start]
if D > P:
total_cost += P
else:
total_cost += D
start = end + 1
print(total_cost)
if __name__ == '__main__':
main()
gew1fw