結果

問題 No.561 東京と京都
ユーザー toshiro_yanagi
提出日時 2022-07-22 01:23:30
言語 Nim
(2.2.0)
結果
WA  
実行時間 -
コード長 735 bytes
コンパイル時間 4,635 ms
コンパイル使用メモリ 65,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 10:04:36
合計ジャッジ時間 3,431 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 8 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils


proc nextStr(): string =
  while not stdin.endOfFile:
    let c = stdin.readChar
    if c == '\r': continue
    if c in [' ', '\n']: break
    result.add(c)


proc main(): void =
  let
    n, d = parseInt(nextStr())
  var
    a = newSeqWith[n+1, [0, 0]]
    ans, p = 0

  for i in 0..<n:
    let t, k = parseInt(nextStr())
    a[i] = [t, k]

  for i in 0..<n:
    let
      noMove1 = a[i][p] + a[i+1][p]
      noMove2 = a[i][p] + a[i+1][(p+1) mod 2] - d
      move1 = a[i][(p+1) mod 2] + a[i+1][(p+1) mod 2] - d
      move2 = a[i][(p+1) mod 2] + a[i+1][p] - 2*d
    if max(noMove1, noMove2) < max(move1, move2):
      p = (p+1) mod 2
      ans -= d
    ans += a[i][p]
  echo ans


when isMainModule: main()
0