# frozen_string_literal: true # Kept libraries: # (none) # Expanded libraries: # - nanacl/array_sum # Errored libraries: # (none) # Removed libraries: # (none) # # ------------------------------------------------------------------------------ # frozen_string_literal: true # This file is expanded by nanacl. main = -> do # ================================================================= # frozen_string_literal: true # require "nanacl/array_sum" # (expanded: L20) 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 } ans = 0.upto(in_n - in_m).map { |s| positives.sum_in_range(s...(s + in_m)) }.max puts ans 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