結果
問題 |
No.595 登山
|
ユーザー |
![]() |
提出日時 | 2025-04-09 21:02:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 460 bytes |
コンパイル時間 | 148 ms |
コンパイル使用メモリ | 82,792 KB |
実行使用メモリ | 120,056 KB |
最終ジャッジ日時 | 2025-04-09 21:04:57 |
合計ジャッジ時間 | 3,619 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 4 WA * 21 |
ソースコード
n, p = map(int, input().split()) h = list(map(int, input().split())) up = [] for i in range(n-1): diff = h[i+1] - h[i] up.append(max(0, diff)) total_up = sum(up) max_gain = 0 current_sum = 0 for u in up: current_sum += u candidate = current_sum - p if candidate > 0: if candidate > max_gain: max_gain = candidate else: current_sum = 0 # Reset if this segment isn't beneficial print(total_up - max_gain)