Skip to content

Instantly share code, notes, and snippets.

@fdutey fdutey/sum.rb
Last active Nov 7, 2017

Embed
What would you like to do?
def parse_arg(arg)
a, b, q = arg.split(' ').map(&:to_i)
[Range.new(a, b), q]
end
inputs = []
while arg = STDIN.gets
inputs << parse_arg(arg)
end
# Drop the first line
input.shift
acc = Hash.new { |h, k|, h[k] = [] }
inputs.each do |r, q|
r.each { |i| acc[i] << q }
end
acc.values.map(&:sum).max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.