eolymp
bolt
Try our new interface for solving problems
Problems

Beautiful Bridges

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. \includegraphics{https://static.eolymp.com/content/m6/m6gg16tgu565v5c0e9nir2jt7s.png} Given a ground profile and a desired bridge height $h$, there are usually many ways of building an arch bridge. We model the ground profile as a piecewise-linear function described by $n$ key points $(x_1, y_1), (x_2, y_2), ..., (x_n, y_n)$, where the $x$-coordinate of a point is the position along the bridge, and the $y$-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 $k$ pillars of heights $h_1, ..., h_k$ that are separated by horizontal distances $d_1, ..., d_{k -1}$ has a total cost of \includegraphics{https://static.eolymp.com/content/g9/g9icduoie14ehbtvs0ild6s9q0.png} for some given constants $α$ and $β$. ABC wants to construct each bridge at the lowest possible cost. \InputFile The first line contains four integers $n$, $h$, $α$ and $β$, where $n~(2 \le n \le 10^4)$ is the number of points describing the ground profile, $h~(1 \le h \le 10^5)$ is the desired height of the bridge above sea level, $α$ and $β~(1 \le α, β \le 10^4)$ are the cost factors as described earlier. Then follow $n$ lines, the $i$-th of which contains two integers $x_i, y_i~(0 \le x_1 < x_2 < ... < x_n \le 10^5$ and $0 \le y_i < h)$, describing the ground profile. \OutputFile Output the minimum cost of building a bridge from horizontal position $x_1$ to $x_n$ at height $h$ above sea level. If it is impossible to build any such bridge, output "\textbf{impossible}".
Time limit 3 seconds
Memory limit 128 MiB
Input example #1
5 60 18 2
0 0
20 20
30 10
50 30
70 20
Output example #1
6460
Input example #2
4 10 1 1
0 0
1 9
9 9
10 0
Output example #2
impossible
Source 2019 ICPC World Finals, Problem B