A. Altruistic Amphibians

Codeforces
IDCF10193A
Time3000ms
Memory512MB
Difficulty
English · Original
Formal · Original
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? The first line of input contains two integers $n$ and $d$ ($1 <= n <= 100 thin 000$, $1 <= d <= 10^8$), where $n$ is the number of frogs and $d$ is the depth of the pit in $mu upright(m)$. Then follow $n$ lines each containing three integers $l, w, h$ ($1 <= l, w, h <= 10^8$), representing a frog with leap capacity $l$ $mu upright(m)$, weight $w$ $mu upright(g)$, and height $h$ $mu upright(m)$. The sum of all frogs' weights is at most $10^8$ $mu upright(g)$. Output the maximum number of frogs that can escape the pit. ## Input The first line of input contains two integers $n$ and $d$ ($1 <= n <= 100 thin 000$, $1 <= d <= 10^8$), where $n$ is the number of frogs and $d$ is the depth of the pit in $mu upright(m)$. Then follow $n$ lines each containing three integers $l, w, h$ ($1 <= l, w, h <= 10^8$), representing a frog with leap capacity $l$ $mu upright(m)$, weight $w$ $mu upright(g)$, and height $h$ $mu upright(m)$. The sum of all frogs' weights is at most $10^8$ $mu upright(g)$. ## Output Output the maximum number of frogs that can escape the pit. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of frogs, $ d \in \mathbb{Z}^+ $ the pit depth. Each frog $ i \in \{1, \dots, n\} $ is characterized by a triple $ (l_i, w_i, h_i) \in \mathbb{Z}^+^3 $: leap capacity, weight, height. **Constraints** 1. $ 1 \leq n \leq 100{,}000 $, $ 1 \leq d \leq 10^8 $ 2. $ 1 \leq l_i, w_i, h_i \leq 10^8 $ for all $ i $ 3. $ \sum_{i=1}^n w_i \leq 10^8 $ **Objective** Maximize the number of frogs that can escape, under the following rules: - A frog $ i $ escapes directly if $ l_i > d $. - A frog $ i $ escapes from a pile of frogs $ \{j_1, j_2, \dots, j_k\} $ (below it) if: $$ h_{j_1} + h_{j_2} + \dots + h_{j_k} + l_i > d $$ - In any pile, the total weight of frogs stacked *on top* of frog $ j $ must be **strictly less** than $ w_j $. - After a frog escapes, all frogs in the pile return to the bottom and may be reused in new piles. - Each frog may escape at most once. Find the maximum number of frogs that can escape via optimal pile formation.
API Response (JSON)
{
  "problem": {
    "name": "A. Altruistic Amphibians",
    "description": {
      "content": "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 ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10193A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of frogs, $ d \\in \\mathbb{Z}^+ $ the pit depth.  \nEach frog $ i \\in \\{1, \\dots, n\\} $ is characterized by a triple $ (l_i, w_i, h_i) \\in \\mat...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments