Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional

Around a circular route, station i has gas[i] fuel and the trip to station i+1 costs cost[i]. With gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2], starting from which station (0-indexed) can you complete the full circle?

  1. A. 3
  2. B. 0
  3. C. 4
  4. D. 2

Correct answer: A. 3

Station 0 has net gas -2 at its first step, so the tank goes negative at once. Starting at station 3 keeps the tank non-negative all the way around.

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

Exams that ask this topic