#P11339. SEGWAY

    ID: 13417 Type: Default 1000ms 256MiB

SEGWAY

SEGWAY

This problem is adapted from COI 2019 T3 [SEGWAY].

In a balance scooter race held in Dubrovnik the track is divided into three segments of 100 metres each (total distance is 300 metres). Because of battery limitations, each contestant determines a strategy beforehand – choosing a pace (in seconds per metre) for the first, second, and third segments. Note that the speeds are given in seconds per metre (hence a larger number means slower progress), and valid speed values lie between 1 and 50.

Along the track there are several accelerator stations. When a contestant reaches an accelerator, if they are not currently benefitting from an accelerator boost, they must use it. The boost immediately gives extra energy so that the scooter travels at a speed of 1 second per metre over an extra distance of $$L = (X \bmod 20),$$ where X is the number of contestants who are strictly ahead at that moment (including those who have already finished).

A contestant cannot trigger a new accelerator until the extra boosted distance is completely exhausted. Note that an accelerator may be used by multiple contestants (simultaneously if necessary) and is never disabled.

Your task is to simulate the race. Assuming that all contestants start at the same time, output the time each contestant takes to reach the finish line.

Note: Throughout the problem, distances are measured in metres and speeds in seconds per metre. Accelerator positions are given along the track and if an acceleration boost would carry a contestant beyond the finish line, only the time until the 300 m mark is counted.

inputFormat

The input begins with two integers N and M on one line, where N (1 ≤ N ≤ 50) is the number of contestants and M (0 ≤ M ≤ 50) is the number of accelerator stations. Each of the next N lines contains three integers v1 v2 v3 (1 ≤ v1, v2, v3 ≤ 50) indicating the contestant’s seconds per metre for the first, second, and third segments respectively.

Then follow M lines, each with one integer D (0 < D < 300) indicating the position (in metres from the start) of an accelerator. The accelerator positions are given in strictly increasing order.

outputFormat

Output N lines. The ith line should contain the total time (in seconds) that the ith contestant takes to finish the 300‐metre race. The answer can be an integer or a decimal value. It is guaranteed that all computations are exact.

sample

2 1
10 10 10
20 20 20
50
2505

5002.5

</p>