Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A problem asks for the minimum number of refuelling stops on a road, where the car has a fuel capacity and each station offers some fuel. Which technique gives the exact optimum in O(n log n)?

  1. A. Greedy: always refuel at the farthest reachable station, using a max-heap of passed stations when the tank runs dry
  2. B. Greedy: always refuel at the first station that you can reach
  3. C. Binary search on the number of stops with a fixed tank size
  4. D. Bitmask DP over all stations, since the order of stops matters

Correct answer: A. Greedy: always refuel at the farthest reachable station, using a max-heap of passed stations when the tank runs dry

Drive until the tank is empty; then retroactively take fuel from the best (largest) station passed so far, which a max-heap gives. Refuelling at the first reachable station can leave a much better station unused.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic