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)?
- A. Greedy: always refuel at the farthest reachable station, using a max-heap of passed stations when the tank runs dry
- B. Greedy: always refuel at the first station that you can reach
- C. Binary search on the number of stops with a fixed tank size
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For the problem 'choose the largest set of non-overlapping intervals', which greedy rule is correct?
- A DP over prefixes of an array computes the number of ways to split it into segments where each segment's sum is at most L. Which…
- Which problem is the standard application of 'binary search on the answer' where the feasibility test itself is a greedy scan?
- In bitmask DP over subsets of n items, what is the typical total time for the TSP-style recurrence dp[mask][last] with transitions to…
- Which statement about the 'house robber' DP on a line is correct?
- A greedy solution to a scheduling problem sorts jobs by profit and places each into the latest free slot before its deadline. What must…