Traffic Light

Source: Codeforces 1744C

  1. Read the problem and summarise the task requirements.

Let’s solve one test case at a time; they are independent of each other. We’ll also start with just a single n-second period, and deal with the repetition later.

  1. Consider a direct execution of the stated task: for every second of the specified colour, scan forward until the next green light, and report the maximum wait time.
  2. How can we make this algorithm faster?
  3. Design an algorithm which finds the next g from each second of the specified colour, using one of the optimisations above.
  4. Write a program which implements your algorithm.
  5. Now, we need to address the repetition of the colours.
  6. Finally, we can deal with the multiple test cases.
  7. Submit your program for judging!