Skip to content

Instantly share code, notes, and snippets.

@niquepa
Last active April 29, 2017 16:21
Show Gist options
  • Save niquepa/f40e008bd264fcbf40c1fdf6cad2c7b7 to your computer and use it in GitHub Desktop.
Save niquepa/f40e008bd264fcbf40c1fdf6cad2c7b7 to your computer and use it in GitHub Desktop.
# Enter your code here. Read input from STDIN. Print output to STDOUT
n = gets.to_i
arr = gets.split(" ")
arr.map! { |i| i.to_i }
#puts arr
arr = arr.permutation(3).to_a.sort.uniq
work = Array.new
arr.each do |perm|
#puts "PERM => #{perm.sort}"
work.push(perm.sort)
end
#work.uniq!
#puts "WORK => #{work}"
resp = Hash.new
max = 0
maxl = 0
maxs = 0
work.each do |tri|
if tri[0] + tri[1] == tri[2] || tri[1] + tri[2] == tri[0] || tri[0] + tri[2] == tri[1]
#puts "ES DEGENERATE #{tri}"
#elsif tri[0] + tri[1] > tri[2] || tri[1] + tri[2] > tri[0] || tri[0] + tri[2] > tri[1]
elsif tri[0] + tri[1] > tri[2]
total = tri.inject {|sum, n| sum.to_i + n.to_i}
resp[total] ||= Array.new
maxl = tri[2] if tri[2] > maxl
maxs = tri[0] if tri[0] > maxs
resp[total].push(tri)
max = total if total > max
else
#puts "NO ES VALIDO #{tri[0]}-#{tri[1]}-#{tri[2]}"
end
end
#puts "RESP => #{resp}"
if resp.count == 0
puts "-1"
elsif resp[max].count == 1
#puts "ONE DOLLAR"
puts resp.values.join(" ")
else
resp = resp[max]
#puts "MAX => #{resp}"
if resp.count == 1
#puts "ONE"
puts resp.join(" ")
else
#puts "VARIOS"
puts ((resp.select {|x| x[2] == maxl}).select {|x| x[0] == maxs}).first.join(" ")
#puts (resp.max_by {|x| x[2]}).join(" ")
#resp.each do |tri|
#puts resp.max_by {|x| x[2]}
#end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment