結果

問題 No.595 登山
ユーザー gew1fw
提出日時 2025-06-12 16:56:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 82,672 KB
実行使用メモリ 120,236 KB
最終ジャッジ日時 2025-06-12 16:56:12
合計ジャッジ時間 4,681 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 5 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0