結果

問題 No.595 登山
ユーザー te-shte-sh
提出日時 2017-11-11 00:11:36
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 494 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 88,400 KB
実行使用メモリ 13,656 KB
最終ジャッジ日時 2023-09-03 16:50:38
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 17 ms
5,952 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 44 ms
12,816 KB
testcase_27 AC 34 ms
12,580 KB
testcase_28 AC 33 ms
12,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], p = rd[1].to!long;
  auto h = readln.split.to!(long[]);

  auto i = 0, j = 0, r = 0L, ans = 0L;
  while (i < n-1 && j < n-1) {
    if (h[j+1] >= h[j]) {
      r += min(h[j+1]-h[j], p);
      ++j;
    } else {
      ans += min(r, p*2);
      r = 0L;
      while (j < n-1 && h[j] > h[j+1]) ++j;
      i = j;
    }
  }
  if (i < j) ans += min(r, p);
  writeln(ans);
}
0