Codeforces Round 274 (Div. 1) |
---|
Finished |
Jaroslav owns a small courier service. He has recently got and introduced a new system of processing parcels. Each parcel is a box, the box has its weight and strength. The system works as follows. It originally has an empty platform where you can put boxes by the following rules:
You can take only the topmost box from the platform.
The system receives n parcels, the i-th parcel arrives exactly at time ini, its weight and strength are equal to wi and si, respectively. Each parcel has a value of vi bourles. However, to obtain this value, the system needs to give the parcel exactly at time outi, otherwise Jaroslav will get 0 bourles for it. Thus, Jaroslav can skip any parcel and not put on the platform, formally deliver it at time ini and not get anything for it.
Any operation in the problem is performed instantly. This means that it is possible to make several operations of receiving and delivering parcels at the same time and in any order.
Please note that the parcel that is delivered at time outi, immediately gets outside of the system, and the following activities taking place at the same time are made without taking it into consideration.
Since the system is very complex, and there are a lot of received parcels, Jaroslav asks you to say what maximum amount of money he can get using his system.
The first line of the input contains two space-separated integers n and S (1 ≤ n ≤ 500, 0 ≤ S ≤ 1000). Then n lines follow, the i-th line contains five space-separated integers: ini, outi, wi, si and vi (0 ≤ ini < outi < 2n, 0 ≤ wi, si ≤ 1000, 1 ≤ vi ≤ 106). It is guaranteed that for any i and j (i ≠ j) either ini ≠ inj, or outi ≠ outj.
Print a single number — the maximum sum in bourles that Jaroslav can get.
3 2
0 1 1 1 1
1 2 1 1 1
0 2 1 1 1
3
5 5
0 6 1 2 1
1 2 1 1 1
1 3 1 1 1
3 6 2 1 2
4 5 1 1 1
5
Note to the second sample (T is the moment in time):
Note that you could have skipped the fourth parcel and got the fifth one instead, but in this case the final sum would be 4 bourles.
Name |
---|