PivotOJ

Driving Lanes

시간 제한: 2000ms메모리 제한: 512MB출처: ICPC Rocky Mountain Regional 2018BOJ 22283

문제

While driving around a curve on the highway, Sam realizes that if they use the inside lane, they travel a shorter distance. Sam wonders what is the minimum distance needed to travel to the destination.

The multilane highway consists of a sequence of straightaways that are connected by curves. When going around a curve, the distance travelled depends on which lane you are in. Each curve has a curvature cc and stretch ss. Specifically, if Sam is in lane ii, then they travel s+cis + c \cdot i meters while going around this curve.

Whenever Sam is on a straightaway, they may change from one lane into an adjacent lane.  When changing to an adjacent lane, Sam moves forward kk meters, but travels a total of k+rk+r meters.  Each lane change must be completed before the car reaches the end of the current straightaway.  Sam may change lanes multiple times in the same straightaway. For safety reasons, changing lanes is not possible on curves.

Sam starts in lane 11 and wishes to end in lane 11. What is the minimum distance they must travel?

입력

The first line of input contains two integers nn (1n2501 \leq n \leq 250), which is the number of straightaways, and mm (1m2501 \leq m \leq 250), which is the number of lanes on the highway. The lanes are numbered 1,2,,m1, 2, \dots, m.

The second line of input contains two integers kk (1k1061 \leq k \leq 10^6) and rr (1r1061 \leq r \leq 10^6), which are the lane changing parameters.

The next nn lines describe the straightaways in order. Each of these lines contains a single integer \ell (11061 \leq \ell \leq 10^6), which is the length of this straightaway.

The next n1n-1 lines describe the curves in order. Each of these lines contains two integers ss (1s1061 \leq s \leq 10^6), which is the stretch of this curve, and cc (106c106-10^6 \leq c \leq 10^6), which is the curvature of this curve. It is guaranteed that s+cm>0s + c \cdot m > 0.

The iith curve connects the iith and (i+1)(i+1)th straightaway.

출력

Display the minimum distance Sam must travel.

예제

예제 1

입력
4 3
5 2
10
10
10
10
4 -1
4 -1
4 1
출력
51

예제 2

입력
4 3
5 2
10
10
10
10
10 -3
10 -3
10 1
출력
61
코드를 제출하려면 로그인하세요.