Codeforces Round 274 (Div. 1)
D
Parcels
Codeforces
2600
原题
← CE →
翻译中…

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:

翻译中…
  • If the platform is empty, then the box is put directly on the platform, otherwise it is put on the topmost box on the platform.
  • The total weight of all boxes on the platform cannot exceed the strength of platform $*S*$ at any time.
  • The strength of any box of the platform at any time must be no less than the total weight of the boxes that stand above.
翻译中…

You can take only the topmost box from the platform.

翻译中…

The system receives $*n*$ parcels, the $*i*$-th parcel arrives exactly at time $*in*_{*i*}$, its weight and strength are equal to $*w*_{*i*}$ and $*s*_{*i*}$, respectively. Each parcel has a value of $*v*_{*i*}$ bourles. However, to obtain this value, the system needs to give the parcel exactly at time $*out*_{*i*}$, 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 $*in*_{*i*}$ 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 $*out*_{*i*}$, 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.

翻译中…

Input

翻译中…

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: $*in*_{*i*}$, $*out*_{*i*}$, $*w*_{*i*}$, $*s*_{*i*}$ and $*v*_{*i*}$ ($0 ≤ *in*_{*i*} < *out*_{*i*} < 2*n*$, $0 ≤ *w*_{*i*}, *s*_{*i*} ≤ 1000$, $1 ≤ *v*_{*i*} ≤ 10^{6}$). It is guaranteed that for any $*i*$ and $*j*$ ($*i* ≠ *j*$) either $*in*_{*i*} ≠ *in*_{*j*}$, or $*out*_{*i*} ≠ *out*_{*j*}$.

翻译中…

Output

翻译中…

Print a single number — the maximum sum in bourles that Jaroslav can get.

翻译中…

Note

翻译中…

Note to the second sample ($*T*$ is the moment in time):

翻译中…
  • $*T* = 0$: The first parcel arrives, we put in on the first platform.
  • $*T* = 1$: The second and third parcels arrive, we put the third one on the current top (i.e. first) parcel on the platform, then we put the secod one on the third one. Now the first parcel holds weight $*w*_{2} + *w*_{3} = 2$ and the third parcel holds $*w*_{2} = 1$.
  • $*T* = 2$: We deliver the second parcel and get $*v*_{2} = 1$ bourle. Now the first parcel holds weight $*w*_{3} = 1$, the third one holds 0.
  • $*T* = 3$: The fourth parcel comes. First we give the third parcel and get $*v*_{3} = 1$ bourle. Now the first parcel holds weight 0. We put the fourth parcel on it — the first one holds $*w*_{4} = 2$.
  • $*T* = 4$: The fifth parcel comes. We cannot put it on the top parcel of the platform as in that case the first parcel will carry weight $*w*_{4} + *w*_{5} = 3$, that exceed its strength $*s*_{1} = 2$, that's unacceptable. We skip the fifth parcel and get nothing for it.
  • $*T* = 5$: Nothing happens.
  • $*T* = 6$: We deliver the fourth, then the first parcel and get $*v*_{1} + *v*_{4} = 3$ bourles for them.
翻译中…

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.

翻译中…

样例

Input #1
3 2
0 1 1 1 1
1 2 1 1 1
0 2 1 1 1
Output #1
3
InputCopy OutputCopy
Input #2
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
Output #2
5
InputCopy OutputCopy
题目信息
题号
480D
时间限制
2 s
内存限制
256 MB
标签
动态规划
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。