結果

問題 No.1767 BLUE to RED
ユーザー tomeruntomerun
提出日時 2021-11-26 23:01:39
言語 Crystal
(1.10.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 19,761 ms
コンパイル使用メモリ 254,516 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2023-09-12 05:26:39
合計ジャッジ時間 21,787 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,432 KB
testcase_02 AC 3 ms
4,468 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,508 KB
testcase_05 AC 2 ms
4,460 KB
testcase_06 AC 2 ms
4,460 KB
testcase_07 AC 3 ms
4,492 KB
testcase_08 AC 3 ms
4,552 KB
testcase_09 AC 40 ms
19,920 KB
testcase_10 AC 52 ms
25,724 KB
testcase_11 AC 45 ms
20,088 KB
testcase_12 AC 40 ms
19,888 KB
testcase_13 AC 57 ms
25,776 KB
testcase_14 AC 74 ms
34,724 KB
testcase_15 AC 75 ms
34,816 KB
testcase_16 AC 75 ms
34,728 KB
testcase_17 AC 77 ms
34,660 KB
testcase_18 AC 76 ms
34,628 KB
testcase_19 AC 75 ms
34,764 KB
testcase_20 AC 75 ms
34,812 KB
testcase_21 AC 75 ms
34,796 KB
testcase_22 AC 76 ms
34,768 KB
testcase_23 AC 75 ms
34,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = read_line.split.map(&.to_i)
a = read_line.split.map(&.to_i)
b = read_line.split.map(&.to_i)
ans = 0
bi = 0
if b[0] < a[0]
  ans += a[0] - b[0]
  while bi < m && b[bi] < a[0]
    bi += 1
  end
end
(n - 1).times do |i|
  nbi = bi
  bs = [] of Int32
  while nbi < m && b[nbi] < a[i + 1]
    bs << b[nbi]
    nbi += 1
  end
  if !bs.empty?
    ds = [bs[0] - a[i], a[i + 1] - bs[-1]]
    (bs.size - 1).times do |j|
      ds << bs[j + 1] - bs[j]
    end
    ans += a[i + 1] - a[i] - ds.max
  end
  bi = nbi
end
if b[-1] > a[-1]
  ans += b[-1] - a[-1]
end
puts ans
0