#K96317. Minimum Total Waiting Time Calculation

    ID: 39060 Type: Default 1000ms 256MiB

Minimum Total Waiting Time Calculation

Minimum Total Waiting Time Calculation

You are given N intersections. Each intersection has a configured number of traffic lights. For the ith intersection, the first number denotes the number of traffic lights, L_i, and is followed by 2L_i integers representing the durations of the green and red phases respectively.

The total waiting time at an intersection is defined as:

$$\text{Waiting Time} = \sum_{j=1}^{L_i}(G_j + R_j) $$

where \( G_j \) is the duration of the green phase and \( R_j \) is the duration of the red phase for the jth traffic light.

Your task is to compute the minimum total waiting time for each intersection over one complete cycle.

inputFormat

The input is given via standard input (stdin) and has the following format:

N
L1 G1 R1 G2 R2 ...
L2 G1 R1 G2 R2 ...
... (total N lines for intersections)

Here, the first line contains a single integer N which represents the number of intersections. The next N lines each start with an integer Li (the number of traffic lights at intersection i), followed by 2Li space-separated integers representing the duration of green and red lights respectively.

outputFormat

Output via standard output (stdout) a single line containing N integers. Each integer represents the total waiting time for the corresponding intersection, calculated as the sum of all green and red light durations. The results should be space-separated.

## sample
3
2 3 5 2 6
3 1 2 2 1 1 1
1 10 15
16 8 25