Created
October 25, 2017 15:54
-
-
Save sarcilav/16bd60f2d63de68b62a263e6d1efce18 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
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