class DifferenceAverage attr_reader :n, :k, :numbers def initialize(n: 0, k: 0, numbers: []) @n, @k, @numbers = n, k, numbers end def cause begin @n = Integer(gets.chomp) @k = Integer(gets.chomp) @numbers = @n.times.map { Integer(gets.chomp) } rescue end end def result @numbers = @numbers.sort puts @numbers[-1] - @numbers[0] end def run cause result end end if $0 == __FILE__ DifferenceAverage.new.run end