結果

問題 No.595 登山
ユーザー te-shte-sh
提出日時 2017-11-10 23:50:30
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 599 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 102,284 KB
実行使用メモリ 13,196 KB
最終ジャッジ日時 2024-06-12 22:28:20
合計ジャッジ時間 2,444 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,812 KB
testcase_03 AC 1 ms
6,944 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
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 48 ms
13,196 KB
testcase_27 AC 35 ms
12,412 KB
testcase_28 AC 35 ms
12,596 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 calc(int i, int j)
  {
    auto r = 0;
    r += min(h[j]-h[i], p);
    if (j-i > 1 && j < n-1) {
      r += min(h[j]-h[i], p);
    }
    return r;
  }

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