Logo
(追記) (追記ここまで)

16315번 - Altruistic Amphibians 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB90383547.945%

문제

A set of frogs have accidentally fallen to the bottom of a large pit. Their only means of escaping the pit is to jump out of it. Each frog i is described by three parameters (li, wi, hi) where li is its leap capacity, wi its weight, and hi its height. The leap capacity specifies how high that frog can jump. If a frog’s leap capacity is strictly larger than the depth of the pit, the frog can directly escape the pit. However, these frogs are altruistic. Rather than selfishly saving themselves and leaving the frogs with too limited leap capacity behind, they collectively aim to save as many of them from the pit as possible.

The frogs realize that if a frog A climbs up on the back of frog B before it jumps, the first frog A stands a better chance of escaping the pit: it can escape if hB + lA is strictly larger than the depth of the pit.

Furthermore, if frog B carrying frog A on its back climbs up on the back of frog C, the situation is even better for frog A: it can now escape the pit if hC + hB + lA is strictly larger than the depth of the pit.

The frogs can build even higher piles of frogs this way, the only restriction is that no frog may carry other frogs of weight in total amounting to its own weight or heavier. Once a pile has been used to allow a frog to escape, the frogs in the pile jump back to the bottom of the pit and they can then form a new pile (possibly consisting of a different set of frogs). The question is simply how many frogs can escape the pit assuming they collaborate to maximize this number?

입력

The first line of input contains two integers n and d (1 ≤ n ≤ 100 000, 1 ≤ d ≤ 108), where n is the number of frogs and d is the depth of the pit in µm. Then follow n lines each containing three integers l, w, h (1 ≤ l, w, h ≤ 108), representing a frog with leap capacity l µm, weight w µg, and height h µm. The sum of all frogs’ weights is at most 108 µg.

출력

Output the maximum number of frogs that can escape the pit.

제한

예제 입력 1

3 19
15 5 3
12 4 4
20 10 5

예제 출력 1

3

예제 입력 2

3 19
14 5 3
12 4 4
20 10 5

예제 출력 2

2

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2018 A번

  • 문제를 만든 사람: Andreas Björklund
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /