class Beans attr_reader :k, :n, :f, :a def initialize(k: 0, n: 0, f: 0, a: []) @k, @n, @f, @a = k, n, f, a end def datainput begin @k, @n, @f = gets.chomp.split.map { |v| Integer(v) } @a = gets.chomp.split.map { |v| Integer(v) } rescue end end def remaining_beans(k, n, a) r = k * n - a.inject(:+) (r < 0)? -1 : r end def dataoutput puts remaining_beans(@k, @n, @a) end def run datainput dataoutput end end if $0 == __FILE__ Beans.new.run end