405387: GYM101933 A Altruistic Amphibians

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Altruistic Amphibianstime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

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 $$$(l_i,w_i,h_i)$$$ where $$$l_i$$$ is its leap capacity, $$$w_i$$$ its weight, and $$$h_i$$$ 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 $$$h_B+l_A$$$ 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 $$$h_C+h_B+l_A$$$ 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?

Input

The first line of input contains two integers $$$n$$$ and $$$d$$$ ($$$1 \le n \leq 100\,000$$$, $$$1 \le d \le 10^8$$$), where $$$n$$$ is the number of frogs and $$$d$$$ is the depth of the pit in $$$\mu\mathrm{m}$$$. Then follow $$$n$$$ lines each containing three integers $$$l, w, h$$$ ($$$1 \le l, w, h \le 10^8$$$), representing a frog with leap capacity $$$l$$$ $$$\mu\mathrm{m}$$$, weight $$$w$$$ $$$\mu\mathrm{g}$$$, and height $$$h$$$ $$$\mu\mathrm{m}$$$. The sum of all frogs' weights is at most $$$10^8$$$ $$$\mu\mathrm{g}$$$.

Output

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

ExamplesInput
3 19
15 5 3
12 4 4
20 10 5
Output
3
Input
3 19
14 5 3
12 4 4
20 10 5
Output
2

加入题单

上一题 下一题 算法标签: