Under construction

Still being built. Things may change

Games

Time limit2sMemory limit1024 MB

Summary
Each game's rules must be learned once before unlimited replays, and the task asks for the maximum total rating reachable within d minutes.
Level

Medium6 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

Kile has returned from a board game fair with nn games. Before playing a game, he must learn its rules. Learning the rules of the ii-th game takes pip_i minutes. Once the rules are learned, the game can be played. Playing the ii-th game takes tit_i minutes. Each game also has its own rating oio_i.

In the coming days, Kile plans to spend at most dd minutes on board games. He wants the maximum sum of ratings of the games he can play. Each game can be played an arbitrary number of times.

Input

The first line contains integers nn and dd (1≤n,d≤50001 \le n, d \le 5000), the number of games and the time planned for playing games.

The ii-th of the following nn lines contains integers pip_i, tit_i and oio_i (0≤pi≤50000 \le p_i \le 5000, 1≤ti≤50001 \le t_i \le 5000, 1≤oi≤1091 \le o_i \le 10^9), the time required to learn the rules, the time required to play, and the rating of the ii-th game.

Output

Print the maximum sum of the ratings of the games played on a single line.

Examples3

  1. Example 1

    Input
    3 10
    2 3 5
    5 1 5
    3 2 5
    
    Expected output
    25
    
  2. Example 2

    Input
    4 13
    0 6 5
    0 3 4
    0 2 3
    0 4 4
    
    Expected output
    19
    
  3. Example 3

    Input
    3 10
    1 1 1
    3 2 3
    2 3 5
    
    Expected output
    11