Skip to content

Instantly share code, notes, and snippets.

@jimmyken793
Created December 4, 2014 15:54
Show Gist options
  • Save jimmyken793/4e30cb47ce7a9b22dd3e to your computer and use it in GitHub Desktop.
Save jimmyken793/4e30cb47ce7a9b22dd3e to your computer and use it in GitHub Desktop.
# 1
puts (1..(gets.to_i)).map{gets.to_i}.reduce(0,:+)
#2
puts (1..(gets.to_i)).map{
t,s,p = gets.split(' ').map{|s| s.to_i}
t <= s ? 0 : (t-s)*p
}.reduce(0, :+)
# 3
mask_size, len = gets.split(" ").map{|s|s.to_i}
max = 0
arr=[]
sum = 0
(0..len-1).each{
arr.push gets.to_i
if arr.size==mask_size
max = sum = arr.reduce(0, :+)
elsif arr.size > mask_size
sum = sum - arr.shift + arr.last
max = [max, sum].max
end
}
puts"#{max}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment