n,x=gets.split.map(&:to_i);k=s=0
a=$<.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|d,m=t.divmod(x);a==n||a.any?{|u|s<=a[d][4]+[u[0],a[d][0]].min+m*u[2]+[0,m-u[1]].max*(u[3]-u[2])}}