Igre

시간 제한2초메모리 제한1024 MB

요약
규칙 학습 시간과 플레이 시간의 합이 d분을 넘지 않도록 게임을 골라 여러 번 플레이할 때 얻을 수 있는 평점 합의 최댓값을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 그리디, 정렬
정답자
아직 제출이 없습니다

문제

Kile has returned from a board game fair. He brought home n games. Before playing a game, it is necessary to learn its rules. Learning the rules of the ii-th game takes p_ip\_i minutes. Once the rules are learned, it is possible to play the game. Playing the ii-th game takes t_it\_i minutes. Each game also has its own rating o_io\_i.

In the coming days, Kile has planned to spend at most dd minutes on board games. He is interested in finding out the maximum sum of the ratings of the games he can play. Each game can be played an arbitrary number of times.

입력

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

The ii-th of the following nn lines contains integers p_ip\_i, t_it\_i and o_io\_i (0≤p_i≤50000 ≤ p\_i ≤ 5000, 1≤t_i≤50001 ≤ t\_i ≤ 5000, 1≤o_i≤1091 ≤ o\_i ≤ 10^9), time required to learn the rules, time required to play and the rating of ii-th game.

출력

In the first and only line, output the maximum sum of the ratings of the games played.

예제3

  1. 예제 1

    입력
    3 10
    2 3 5
    5 1 5
    3 2 5
    
    예상 출력
    25
    
  2. 예제 2

    입력
    4 13
    0 6 5
    0 3 4
    0 2 3
    0 4 4
    
    예상 출력
    19
    
  3. 예제 3

    입력
    3 10
    1 1 1
    3 2 3
    2 3 5
    
    예상 출력
    11