Skip to content

Instantly share code, notes, and snippets.

@danny8376
Created December 4, 2014 19:24
Show Gist options
  • Save danny8376/30cf12611180b6e934a3 to your computer and use it in GitHub Desktop.
Save danny8376/30cf12611180b6e934a3 to your computer and use it in GitHub Desktop.
# 自分の得意な言語で
# Let's チャレンジ!!
# Rubyは怖いです
# too slow QQ
=begin
block, total = gets.split(" ").map{|i| i.to_i}
pieces = total.times.map{gets.to_i}
puts (0..total-block).map { |i|
pieces[i, block].inject(&:+)
}.max
=end
# ... It's not so pretty T_T
block, total = gets.split(" ").map{|i| i.to_i}
pieces = total.times.map{gets.to_i}
# block calcing now = max value found = total of first block (?)
block_total = max_now = pieces[0, block].inject(&:+)
(block...total).each do |i|
block_total = block_total - pieces[i - block] + pieces[i]
max_now = block_total if block_total > max_now
end
puts max_now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment