Feeding Geese

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

요약
거위 i는 [T_i, T_i+L] 동안 먹이를 받을 수 있고, 먹이를 던지면 그 시각에 기다리는 거위 중 속도 A_i가 가장 큰 거위가 먹이를 가져가며 그 거위의 귀여움 C_i가 점수에 더해진다. 먹이를 원하는 만큼 던질 수 있을 때 얻을 수 있는 최대 점수를 구한다.
난이도

어려움10점 중 8점

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

문제

There are NN adorable geese in KAIST campus. To celebrate these lovely creatures, KAIST will host “KAIST Geese Show” for students. The main contents of the show is simply feeding the geese and enjoying their delightful reactions.

You have the honor of being chosen as the representative feeder. Your mission is to make the show as cute as possible by feeding the geese optimally. The ii-th goose approaches you at time T_iT\_i and will eagerly wait for food for a duration of LL. More precisely, the ii-th goose is available to eat food during the time interval T_i≤x≤T_i+LT\_i\le x\le T\_i+L. After time T_i+LT\_i+L, the goose will lose interest and leave.

The ii-th goose has speed level of A_iA\_i and cuteness of C_iC\_i. If you throw a food to the awaiting geese at any time, the fastest goose (highest A_iA\_i) among those will take it. Then the goose will proudly display its cuteness for all to see, adding its cuteness value to the overall cuteness score of the show. After consuming a food, the goose will satisfy and leave. Note that there are no two geese having same speed level. Also, there can be some noisy goose, so C_iC\_i may be negative.

You have the freedom to throw as much food as you desire, with no constraints on frequency or quantity. Your goal is to determine the maximum cuteness score achievable for the show.

입력

The first line contains space-separated two integers, NN, LL.

The next NN lines contain space-separated three integers, the ii-th line contains A_i,C_i,T_iA\_i,C\_i,T\_i.

출력

Output the maximum cuteness score of the show.

제한

  • 1≤N≤300,0001\le N\le 300\\, 000
  • 1≤L≤1091\le L\le 10^9
  • 1≤A_i≤N (1≤i≤N)1\le A\_i\le N\ (1\le i\le N)
  • A_i≠A_jA\_i\neq A\_j if i≠j (1≤i,j≤N)i\neq j\ (1\le i,j\le N)
  • −109≤C_i≤109 (1≤i≤N)-10^9\le C\_i\le 10^9\ (1\le i\le N)
  • 0≤T_i≤109 (1≤i≤N)0\le T\_i\le 10^9\ (1\le i\le N)
  • All values in the input are integers.

예제1

  1. 예제 1

    입력
    6 5
    6 -1 7
    4 -5 9
    1 3 11
    5 -4 13
    2 4 14
    3 6 7
    
    예상 출력
    9