#P3299. Plant Defense
Plant Defense
Plant Defense
In this problem, you are participating in SDOI2013 and must protect the problem setter from an onslaught of zombies attacking his house. In each level, a queue of zombies is approaching along a straight line. The details for the i-th level are as follows:
- The front zombie (i.e. the one closest to the house) has health \(a_i\), the second zombie has health \(a_{i-1}\), and so on until the last zombie which has health \(a_1\).
- The front zombie starts at a distance \(x_i\) from the house. Each subsequent zombie is placed exactly \(d\) meters behind the previous zombie. Hence, the j-th zombie in the queue starts at a distance \(x_i+(j-1)d\) from the house.
- All zombies move at a constant speed of 1 m/s toward the house.
- You place a plant at the door which can shoot an attack dealing \(y_i\) damage per second. The plant always targets the zombie at the front. When the front zombie is killed, the next zombie immediately becomes the target and starts taking damage.
To clear a level, each zombie must be eliminated before it reaches the house. For a given level, assume that when the zombies appear, the plant is set with the minimum required attack power (y_i) so that for every (1 \le j \le i) (where j = 1 corresponds to only the front zombie being alive and j = i corresponds to all zombies being alive), the following inequality holds:
[ \frac{\sum_{k=i-j+1}^{i}a_k}{y_i} \le x_i + (j-1)d ]
Thus the minimal required attack power for that level is:
[ y_i = \max_{1 \le j \le i} \frac{\sum_{k=i-j+1}^{i} a_k}{x_i + (j-1)d} ]
Your task is to compute the minimal total attack power over all levels:
[ \text{Score} = \sum_{i=1}^{n} y_i ]
Print the answer with at least 6 decimal places.
inputFormat
The first line contains two integers (n) and (d) where (n) is the number of levels and (d) is the constant distance between consecutive zombies in a level.
For the next (n) lines, the i-th line describes the i-th level. It begins with a number (x_i) (the starting distance of the front zombie from the house), followed by (i) integers representing the health values (a_1, a_2, \ldots, a_i). Note that the front zombie is represented by (a_i), the next by (a_{i-1}), and so on.
outputFormat
Output a single number—the minimal total plant attack power required over all levels. The result must be printed with at least 6 decimal places.
sample
1 1
10 5
0.500000
</p>