Skip to content

Instantly share code, notes, and snippets.

@takano32
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takano32/9d4b03ca5fd0c8e2a92c to your computer and use it in GitHub Desktop.
Save takano32/9d4b03ca5fd0c8e2a92c to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
input_lines = ARGF
first = true
sum = 0
input_lines.each_line do |line|
if first then
first = false
next
end
t, s, p = (line.split ' ').map {|s| s.to_i}
if not t <= s then
sum += (t - s) * p
end
end
puts sum
#!/usr/bin/env ruby
#
input_lines = ARGF.read
t = 0
n = 0
m = []
first = true
input_lines.each_line do |line|
if first then
first = false
t, n = (line.split ' ').map {|s| s.to_i}
next
end
m << line.strip.to_i
end
max = 0
m.each_cons(t) do |ms|
v = ms.inject(:+)
if max < v then
max = v
end
end
puts max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment