#C5114. Traffic System Simulation
Traffic System Simulation
Traffic System Simulation
You are given a grid representing a city with intersections, each with an initial waiting count of cars and a traffic light state. The traffic lights can be either red (R) or green (G). You are also given a set of rules that may change the traffic light state at specific time intervals if the waiting count is high enough.
The simulation runs for \(t\) time steps. At each time step, for every rule \((a, b, c)\), if the current time step \(s\) satisfies \(a \le s \le b\), then every intersection with waiting count greater than or equal to \(c\) will have its light switched to green. After processing all rules in a time step, the waiting time contributed by all intersections with red lights is added to the total waiting time.
Your task is to simulate the traffic system and output the total waiting time of all intersections after \(t\) time steps.
inputFormat
The input consists of multiple test cases. For each test case:
- The first line contains three integers: \(N\) (number of rows), \(M\) (number of columns), and \(t\) (number of time steps).
- The next \(N\) lines each contain \(M\) integers representing the waiting counts at each intersection.
- The following \(N\) lines each contain \(M\) characters (either 'R' or 'G') representing the initial state of the traffic lights.
- Then follows a sequence of lines, each with three integers \(a\), \(b\), and \(c\) representing a traffic light switching rule. This sequence is terminated by a line containing "0 0 0" (which should not be processed).
The input terminates with a test case where \(N = 0\), \(M = 0\), and \(t = 0\), which should not be processed.
outputFormat
For each test case, output a single integer: the total waiting time accumulated over all time steps. Each result should be printed on its own line.
## sample2 2 3
1 2
3 4
R G
G R
1 3 3
0 0 0
0 0 0
3
</p>