Created
December 4, 2014 19:24
-
-
Save danny8376/30cf12611180b6e934a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 自分の得意な言語で | |
# 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