Driving Lanes
문제
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 and stretch . Specifically, if Sam is in lane , then they travel 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 meters, but travels a total of 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 and wishes to end in lane . What is the minimum distance they must travel?
입력
The first line of input contains two integers (), which is the number of straightaways, and (), which is the number of lanes on the highway. The lanes are numbered .
The second line of input contains two integers () and (), which are the lane changing parameters.
The next lines describe the straightaways in order. Each of these lines contains a single integer (), which is the length of this straightaway.
The next lines describe the curves in order. Each of these lines contains two integers (), which is the stretch of this curve, and (), which is the curvature of this curve. It is guaranteed that .
The th curve connects the th and 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