Rectangles Inside Rectangle

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Bobo has a large rectangle with lower left and upper right corners at (0,0)(0, 0) and (w,106)(w, 10^6). He also has nn small axis-parallel rectangles inside the large rectangle. The weight of the ii-th rectangle is v_iv\_i. For each rectangle, either its left border or its right border (but not both) coincides with the left or right side of the large rectangle.

Bobo would like to choose a subset of small rectangles in such a manner that the rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Among all the possibilities, he wants the one with the maximum possible sum of weights.

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains two integers nn and ww (1n20001 \leq n \leq 2000, 2w1062 \leq w \leq 10^6) denoting the number of small rectangles and the width of the large rectangle.

The ii-th of the following nn lines contains five integers type_i\mathit{type}\_i, l_il\_i, a_ia\_i, b_ib\_i and v_iv\_i (type_i0,1\mathit{type}\_i \in \\{0, 1\\}, 0a_i<b_i1060 \leq a\_i < b\_i \leq 10^6, 1l_i<w1 \leq l\_i < w, 0v_i1060 \leq v\_i \leq 10^6) where v_iv\_i is the weight of the ii-th rectangle. Here, type_i=0\mathit{type}\_i = 0 means the lower left and upper right corner of the ii-th rectangle are (0,a_i)(0, a\_i) and (l_i,b_i)(l\_i, b\_i), while type_i=1\mathit{type}\_i = 1 means the lower left and upper right corner of the ii-th rectangle are (wl_i,a_i)(w - l\_i, a\_i) and (w,b_i)(w, b\_i).

It is guaranteed that for all 1i<jn1 \leq i < j \leq n, a_ia_ja\_i \ne a\_j, a_ib_ja\_i \ne b\_j, b_ia_jb\_i \ne a\_j and b_ib_jb\_i \ne b\_j. Additionally, the sum of all nn does not exceed 20002000.

출력

For each test case, output an integer which denotes the maximum sum of weights.

힌트

For the third test, Bobo can choose the 33-rd, 44-th and 55-th rectangles.