結果

問題 No.595 登山
ユーザー te-shte-sh
提出日時 2017-11-10 23:35:07
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 505 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 88,232 KB
実行使用メモリ 13,220 KB
最終ジャッジ日時 2023-09-03 16:50:27
合計ジャッジ時間 2,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 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 WA -
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 1 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 42 ms
12,812 KB
testcase_27 AC 30 ms
12,476 KB
testcase_28 AC 31 ms
12,480 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, ans = 0L;
  while (i < n-1 && j < n-1) {
    if (h[j+1] >= h[j]) {
      ++j;
    } else {
      ans += min(h[j]-h[i], p);
      if (j - i > 1) {
        ans += min(h[j]-h[i+1], p);
      }
      while (j < n-1 && h[j] > h[j+1]) ++j;
      i = j;
    }
  }
  if (i < j) ans += p;
  writeln(ans);
}
0