402191: GYM100694 A Did he drop any good loot?

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Did he drop any good loot?time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Slava plays a very cool RPG. He has just cleaned up the dungeon, and n cool artifacts have been dropped down. He wants to sell them to gain as much profit as he can. Each artifact has its own price pi and weight wi. Slava cannot carry artifacts with the total weight greater than m, but it's possible to activate some of them. Being activated, the i-th artifact increases Slava's strength and adds additional weight di to Slava's weight limit. Activated artifacts don't disappear, their price and weight don't change and they still can be sold. Slava can activate no more than 2 artifacts at the same time.

More formally, Slava wants to choose a set of artifacts with the greatest total price among all correct sets. The set of artifacts i1, i2, ..., ik (k ≤ n) is called correct if wi1 + wi2 + ... + wik ≤ m + s, where s is the additional weight limit gained from the actifacts activation: s = dj1 + dj2, if Slava activated artifacts j1 and j2 (j1 ≠ j2), s = dj — if he activated only artifact j, and s = 0, if he didn't activate any artifacts (j1, j2 and j must be contained in the set of chosen artifacts i1, i2, ..., ik).

Input

The first line contains two space-separated integers n and m (1 ≤ n ≤ 104, 1 ≤ m ≤ 500) — the number of artifacts and the Slava's weight limit.

Each of the next n lines contains three space-separated integers pi, wi and di (1 ≤ pi ≤ 105, 1 ≤ wi ≤ 100, 0 ≤ di ≤ 100) — the price of the i-th artifact, its weight and the additional weight limit it gains at its activation.

Output

Write one integer — the maximum total price of the artifacts Slava can take with him.

ExamplesInput
5 10
1 5 3
2 4 0
3 2 2
4 1 4
5 3 1
Output
15
Input
3 10
100 100 20
200 80 30
300 60 40
Output
0
Note

In the first sample Slava cannot just take all artifacts — his weight limit is 10, and the total weight of all artifacts is 15. That's why he activates artifacts 1 and 4, which leads to increasing his weight limit to 10 + 3 + 4 = 17 (in fact, he can activate any pair of artifacts which increases his weight limit by 5 or more).

In the second sample Slava cannot take any artifacts, either with the activation or without it.

加入题单

算法标签: