Tap here to switch tabs
Problem
Submissions

Problem: Minimize Maximum Waiting Time at Synchronized Lights

Try to solve the Minimize Maximum Waiting Time at Synchronized Lights problem.

Statement

You are given an integer period, an integer array lights, and an integer array arrivalTime.

There are several traffic lights, each operating on a synchronized repeating cycle of length period. For a traffic light with a green duration of lights[i], the light is green from time 00 up to lights[i] (exclusive) within each cycle, and red for the rest of the cycle.

When a vehicle arrives at time t=t = arrivalTime[j], its position within the cycle is r=t mod extperiodr = t \bmod ext{period}:

  • If r<r < lights[i], the traffic light is green, resulting in a waiting time of 00.

  • If r≥r \geq lights[i], the traffic light is red, and the vehicle must wait until the beginning of the next cycle, resulting in a waiting time of period −r- r.

Each vehicle can be assigned to any traffic light in lights independently. The penalty of an assignment is defined as the maximum waiting time among all vehicles.

Return the minimum possible penalty achievable after assigning every vehicle to an optimal traffic light.

Constraints:

  • 2≤2 \leq period ≤109\leq 10^9

  • 1≤1 \leq lights.length ≤104\leq 10^4

  • 1≤1 \leq lights[i] ≤\leq period −1- 1

  • 1≤1 \leq arrivalTime.length ≤105\leq 10^5

  • 1≤1 \leq arrivalTime[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimize Maximum Waiting Time at Synchronized Lights

Try to solve the Minimize Maximum Waiting Time at Synchronized Lights problem.

Statement

You are given an integer period, an integer array lights, and an integer array arrivalTime.

There are several traffic lights, each operating on a synchronized repeating cycle of length period. For a traffic light with a green duration of lights[i], the light is green from time 00 up to lights[i] (exclusive) within each cycle, and red for the rest of the cycle.

When a vehicle arrives at time t=t = arrivalTime[j], its position within the cycle is r=t mod extperiodr = t \bmod ext{period}:

  • If r<r < lights[i], the traffic light is green, resulting in a waiting time of 00.

  • If r≥r \geq lights[i], the traffic light is red, and the vehicle must wait until the beginning of the next cycle, resulting in a waiting time of period −r- r.

Each vehicle can be assigned to any traffic light in lights independently. The penalty of an assignment is defined as the maximum waiting time among all vehicles.

Return the minimum possible penalty achievable after assigning every vehicle to an optimal traffic light.

Constraints:

  • 2≤2 \leq period ≤109\leq 10^9

  • 1≤1 \leq lights.length ≤104\leq 10^4

  • 1≤1 \leq lights[i] ≤\leq period −1- 1

  • 1≤1 \leq arrivalTime.length ≤105\leq 10^5

  • 1≤1 \leq arrivalTime[i] ≤109\leq 10^9