n,x=gets.split.map(&:to_i);k=s=0
q=$<.map{|t|a,b,c=t.split.map(&:to_i);s+=a*b;[(a-x)*c-a*b,a,b,c]}.sort.map{|t|t<<(k-=t[0])}
p (0...n*x).bsearch{|t|f,m=t.divmod(x);f==n||q.any?{|a,b,c,d,e|s<=q[f][4]+[a,q[f][0]].min+m*c+[0,m-b].max*(d-c)}}