import scala.io.StdIn._



object Main extends App {

  val Array(n ,x) = readLine.trim.split(' ').map(_.toInt)
  val tests = Array.tabulate(n){_ ⇒
    val Array(b, l, u) = readLine.trim.split(' ').map(_.toLong)
    Test(b, l, u)
  }.sortBy{test ⇒
    (x - test.score) * test.upper + test.score * test.lower
  }(Ordering.Long.reverse)
  var currentScore = tests.map{t ⇒ t.score * t.lower}.sum
  var currentUse = 0L
  for ((t, i) ← tests.zipWithIndex if currentScore > 0) {
    if (currentScore >= (x - t.score) * t.upper + t.score * t.lower) {
      currentScore -= (x - t.score) * t.upper + t.score * t.lower
      currentUse += x
    }else {
      currentUse += (i until n).map{tests}.map{test ⇒
        if (test.score * test.lower >= currentScore) (currentScore + test.lower - 1) / test.lower
        else (currentScore + test.score * (test.upper - test.lower) + test.upper - 1) / test.upper
      }.min
      currentScore = 0
    }
  }
  println(currentUse)


  case class Test(score: Long, lower: Long, upper: Long)
}
