gets xs = gets.chomp.split tasu = xs.select{|c|c=="+"}.size hiku = xs.select{|c|c=="-"}.size xs = xs.select{|c|c!="+" and c!="-"}.map(&:to_i) xs.sort! xs.reverse! exp = "" i=xs.length tasu.times { i -= 1 exp = "#{exp} #{xs[i]} +" } hiku.times { i -= 1 exp = "#{exp} #{xs[i]} -" } a="" while i>0 do i -= 1 a="#{xs[i]}#{a}" end exp += a mini =eval exp exp = "" i=xs.length hiku.times { i -= 1 exp = "- #{xs[i]} #{exp}" } tasu.times { i -= 1 exp = "+ #{xs[i]} #{exp}" } while i>0 do i -= 1 exp = "#{xs[i]}#{exp}" end maxi = eval exp puts "#{maxi} #{mini}"