Character = Struct.new(:lpt, :atk, :def, :swf)

@n = gets.to_i
Cs = []
(@n+1).times{ Cs << Character.new( *gets.split.map(&:to_i) ) }

Btl = Struct.new(:hpt, :dmg)

def solve
  sum_dmg = 0
  arr = []
  (1..@n).each do |i|
    dmg = [Cs[i].atk - Cs[0].def, 0].max
    hpt = [Cs[0].atk - Cs[i].def, 0].max
    return -1 if dmg > 0 && hpt == 0
    next if hpt == 0
    hpt = (Cs[i].lpt.to_f / hpt).ceil
    sum_dmg -= dmg if Cs[i].swf < Cs[0].swf
    arr << Btl.new(hpt, dmg)
  end
  #cmp h / d
  t = 0
  arr.sort{ |e0, e1| e0.hpt * e1.dmg <=> e0.dmg * e1.hpt }.reduce(sum_dmg){ |sum, btl|
    t += btl.hpt
    return -1 if sum_dmg >= Cs[0].lpt
    sum + btl.dmg * t
  }
end

p solve