Beautiful Bridges
What connects us all? Well, it is often bridges. Since ancient times, people have been building bridges for roads, for trains, for pedestrians, and as aqueducts to transport water. It is humanity’s way of not taking inconvenient geography for an answer.
The company Arch Bridges Construction (ABC) specializes in — you guessed it — the construction of arch bridges. This classical style of bridge is supported by pillars that extend from the ground below the bridge. Arches between pillars distribute the bridge’s weight onto the adjacent pillars.
The bridges built by ABC often have pillars spaced at irregular intervals. For aesthetic reasons, ABC’s bridges always have semicircular arches, as illustrated in Figure B.1. However, while a bridge arch can touch the ground, it cannot extend below the ground. This makes some pillar placements impossible.
Given a ground profile and a desired bridge height , there are usually many ways of building an arch bridge. We model the ground profile as a piecewise-linear function described by key points , where the -coordinate of a point is the position along the bridge, and the -coordinate is the elevation of the ground above sea level at this position along the bridge. The first and last pillars must be built at the first and last key points, and any intermediate pillars can be built only at these key points. The cost of a bridge is the cost of its pillars (which is proportional to their heights) plus the cost of its arches (which is proportional to the amount of material used). So a bridge with pillars of heights that are separated by horizontal distances has a total cost of
for some given constants and . ABC wants to construct each bridge at the lowest possible cost.
Input
The first line contains four integers , , and , where is the number of points describing the ground profile, is the desired height of the bridge above sea level, and are the cost factors as described earlier. Then follow lines, the -th of which contains two integers and , describing the ground profile.
Output
Output the minimum cost of building a bridge from horizontal position to at height above sea level. If it is impossible to build any such bridge, output "impossible".