結果

問題 No.3684 chokudai_niku.png
コンテスト
ユーザー Nanashi.
提出日時 2026-09-05 14:11:37
言語 Ruby
(4.0.6)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 1,267 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 115 ms
コンパイル使用メモリ 9,664 KB
実行使用メモリ 47,576 KB
最終ジャッジ日時 2026-09-05 14:12:24
合計ジャッジ時間 14,613 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:5: warning: 'frozen_string_literal' is ignored after any tokens
Main.rb:27: warning: 'frozen_string_literal' is ignored after any tokens
Syntax OK

ソースコード

diff #
raw source code

# frozen_string_literal: true
# This file is expanded by nanacl.

main = -> do # =================================================================
# frozen_string_literal: true
# require "nanacl/array_sum" # (expanded: L26)
in_n, in_m = gets.chomp.split.map(&:to_i)
in_a = gets.chomp.split.map(&:to_i)
in_b = gets.chomp.split.map(&:to_i)

positives = in_a.zip(in_b).map { |a, b| [a - b, 0].max}

max = 0
(in_n - in_m + 1).times do |i|
  max = [
    0,
    positives.sum_in_range((i)..(i+in_m-1))
  ].max

end
puts max

end # --------------------------------------------------------------------------

# === dependencies -------------------------------------------------------------
# == nanacl/array_sum from main ------------------------------------------------
# frozen_string_literal: true
class Array
  def sum_in_range(range)
    unless @sums
      @sums = [0]
      sum = 0
      each { |v| @sums << (sum += v) }
    end
    range_begin = range.begin || 0
    if range.end.nil?
      @sums[length] - @sums[range_begin]
    elsif range.exclude_end?
      @sums[range.end] - @sums[range_begin]
    else
      @sums[range.end + 1] - @sums[range_begin]
    end
  end
end


# ==============================================================================

main.call
0