Cute Little Butterfly

아직 제출이 없습니다메모리 제한1024 MB

문제

In a forest of the magical world, there lies a garden full of magical creatures. The garden has plenty of flowers which are not just beautiful but also a source of energy for butterflies.

Consider the garden a 2D plane where the X-axis represents the ground, and the Y-axis represents the altitude. There are plants of infinite height on every non-negative integral point on the X-axis. There are N\mathbf{N} flowers in the garden, where the ii-th flower is on the point (X_i\mathbf{X\_i}, Y_i\mathbf{Y\_i}) with the nectar of some energy value C_i\mathbf{C\_i}.

Our cute little butterfly wants as much energy as possible to become strong. By going to the same position of a flower, the butterfly can consume its nectar and gain that flower's energy value. Each flower's nectar can only be consumed once.

The butterfly is initially at point (0,1018)(0, 10^{18}) with 00 units of energy and facing towards the right. At any point, the butterfly can:

  • Move to a lower altitude, that is, from (x,y)(x, y) to (x,y1)(x, y-1) only if its current altitude is positive (y>0y > 0).
  • Move in the positive direction along the X-axis, that is, from (x,y)(x, y) to (x+1,y)(x+1, y) if it is facing right.
  • Move in the negative direction along the X-axis, that is, from (x,y)(x, y) to (x1,y)(x-1, y) if it is facing left.
  • Change the direction it is facing (from left to right or vice versa). This will consume E\mathbf{E} units of energy.

We know our butterfly is lazy, and it hates to move upwards during the journey. So, for this problem, we will assume that going upwards is not allowed. Also, energy can be negative at any point. Negative energy means the butterfly has spent more energy than it obtained from the flowers.

Find the maximum energy our cute butterfly can achieve.

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains two integers, N\mathbf{N} and E\mathbf{E}: the number of flowers and the energy required per turn, respectively.

The next N\mathbf{N} lines describe the flowers. The ii-th line contains three integers, X_i\mathbf{X\_i}, Y_i\mathbf{Y\_i} and C_i\mathbf{C\_i}: the position and the energy value of the ii-th flower, respectively.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the maximum overall energy our cute butterfly can achieve.

제한

  • 1T1001 \le \mathbf{T} \le 100.
  • 0E1090 \le \mathbf{E} \le 10^9.
  • 1C_i1091 \le \mathbf{C\_i} \le 10^9, for all ii.
  • All flowers are located at distinct points.