report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
TOURIST - FlandreOJ: Flandre Online Judge

TOURIST

Time limit: 1000 ms
Memory limit: 256 MB
There are $n$ gas stations located at positions $x_1, x_2, \ldots, x_n$ on a straight line. - Each station $i$ has $f_i$ liters of fuel available. - Each station $i$ has a "threshold" $r_i$. You can only use station $i$ if your **initial fuel capacity** $V$ satisfies $V \le r_i$. You want to travel from position $0$ to position $H$. - Traveling 1 unit of distance consumes 1 liter of fuel. - You choose an initial fuel amount $V$. You start at position $0$ with $V$ liters of fuel. - When you arrive at a station $i$, if $V \le r_i$, you can refuel. Refueling adds $f_i$ to your current fuel. - Your fuel tank has unlimited capacity (you can hold more than $V$ fuel after refueling). - You cannot move if your fuel becomes negative. Find the **minimum** initial fuel $V$ required to travel from $0$ to $H$. #### Input - The first line contains an integer $n$ ($1 \leq n \leq 10^5$) and an integer $H$ ($1 \leq H \leq 10^9$). - The next $n$ lines each contain three integers $x_i, f_i, r_i$ ($0 < x_i < H$, $1 \le f_i, r_i \le 10^9$). #### Output - Output a single integer, the minimum $V$. #### Subtasks - **Subtask 1 (20%):** $H \le 10^4$. - **Subtask 2 (30%):** $n \le 10^4$. - **Subtask 3 (50%):** No additional constraints ($n \le 10^5, H \le 10^9$). #### Example Input: ``` 2 10 3 5 6 7 2 4 ``` Output: ``` 3 ```
PTNK Prelimination - [2025-2026]
PRIME
TOURIST
TRANSPORT
Topic
2026
Rating 800
Solution (0) Solution