Skip to content

Instantly share code, notes, and snippets.

@sarcilav
Created October 25, 2017 15:54
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 sarcilav/16bd60f2d63de68b62a263e6d1efce18 to your computer and use it in GitHub Desktop.
Save sarcilav/16bd60f2d63de68b62a263e6d1efce18 to your computer and use it in GitHub Desktop.
def steps(n, m)
d = n - m
ans = d/5
d = d%5
ans += d/2
d = d%2
ans + d
end
t = gets.to_i
t.times do
n = gets.to_i
c = gets.split.map(&:to_i)
mini = c.min
ms = [mini, mini-1, mini-2]
# puts ms.inspect
puts ms.map {|m|
c.reduce(0) { |acum , n| acum + steps(n, m)}
}.min
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment