結果

問題 No.595 登山
ユーザー square1001square1001
提出日時 2017-11-10 22:49:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 1,500 ms
コード長 388 bytes
コンパイル時間 578 ms
コンパイル使用メモリ 66,336 KB
実行使用メモリ 4,448 KB
最終ジャッジ日時 2023-08-16 03:28:51
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 54 ms
4,380 KB
testcase_05 AC 17 ms
4,380 KB
testcase_06 AC 45 ms
4,376 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 47 ms
4,380 KB
testcase_10 AC 33 ms
4,380 KB
testcase_11 AC 30 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 34 ms
4,376 KB
testcase_15 AC 35 ms
4,376 KB
testcase_16 AC 34 ms
4,380 KB
testcase_17 AC 34 ms
4,376 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 75 ms
4,380 KB
testcase_20 AC 74 ms
4,380 KB
testcase_21 AC 75 ms
4,376 KB
testcase_22 AC 73 ms
4,448 KB
testcase_23 AC 74 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 76 ms
4,376 KB
testcase_27 AC 57 ms
4,376 KB
testcase_28 AC 57 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int n, p, a[200009];
int main() {
	cin >> n >> p;
	for (int i = 0; i < n; i++) cin >> a[i];
	long long lm = 0, rm = 1LL << 60;
	for (int i = 1; i < n; i++) {
		long long v = min(lm, rm) + p;
		lm = min(v, lm + max(a[i] - a[i - 1], 0));
		rm = min(v, rm + max(a[i - 1] - a[i], 0));
	}
	cout << min(lm, rm) << endl;
	return 0;
}
0