結果
| 問題 | No.595 登山 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-11-11 18:47:21 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 27 ms / 1,500 ms | 
| コード長 | 560 bytes | 
| コンパイル時間 | 1,568 ms | 
| コンパイル使用メモリ | 165,928 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-24 19:22:57 | 
| 合計ジャッジ時間 | 3,245 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 25 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll h[200005];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll p;
    cin >> n >> p;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    ll dp = 1000000000000000LL, dp2 = 0;
    for (int i = 1; i < n; i++) {
        ll tmp = min(dp + min(max(h[i - 1] - h[i], 0LL), p), dp2 + p);
        ll tmp2 = min(dp + p, dp2 + min(max(h[i] - h[i - 1], 0LL), p));
        dp = tmp;
        dp2 = tmp2;
    }
    cout << min(dp, dp2) << endl;
    return 0;
}
            
            
            
        