Codeforces Round 366 (Div. 1)
B
Ant Man
Codeforces
2500
原题
← AC →
翻译中…

Scott Lang is at war with Darren Cross. There are $*n*$ chairs in a hall where they are, numbered with $1, 2, ..., *n*$ from left to right. The $*i*$-th chair is located at coordinate $*x*_{*i*}$. Scott is on chair number $*s*$ and Cross is on chair number $*e*$. Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number $*s*$), visit each chair exactly once and end up on chair number $*e*$ with Cross.

翻译中…

As we all know, Scott can shrink or grow big (grow big only to his normal size), so at any moment of time he can be either small or large (normal). The thing is, he can only shrink or grow big while being on a chair (not in the air while jumping to another chair). Jumping takes time, but shrinking and growing big takes no time. Jumping from chair number $*i*$ to chair number $*j*$ takes $|*x*_{*i*} - *x*_{*j*}|$ seconds. Also, jumping off a chair and landing on a chair takes extra amount of time.

翻译中…

If Scott wants to jump to a chair on his left, he can only be small, and if he wants to jump to a chair on his right he should be large.

翻译中…

Jumping off the $*i*$-th chair takes:

翻译中…
  • $*c*_{*i*}$ extra seconds if he's small.
  • $*d*_{*i*}$ extra seconds otherwise (he's large).
翻译中…

Also, landing on $*i*$-th chair takes:

翻译中…
  • $*b*_{*i*}$ extra seconds if he's small.
  • $*a*_{*i*}$ extra seconds otherwise (he's large).
翻译中…

In simpler words, jumping from $*i*$-th chair to $*j*$-th chair takes exactly:

翻译中…
  • $|*x*_{*i*} - *x*_{*j*}| + *c*_{*i*} + *b*_{*j*}$ seconds if $*j* < *i*$.
  • $|*x*_{*i*} - *x*_{*j*}| + *d*_{*i*} + *a*_{*j*}$ seconds otherwise ($*j* > *i*$).
翻译中…

Given values of $*x*$, $*a*$, $*b*$, $*c*$, $*d*$ find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.

翻译中…

Input

翻译中…

The first line of the input contains three integers $*n*, *s*$ and $*e*$ ($2 ≤ *n* ≤ 5000, 1 ≤ *s*, *e* ≤ *n*, *s* ≠ *e*$) — the total number of chairs, starting and ending positions of Scott.

翻译中…

The second line contains $*n*$ integers $*x*_{1}, *x*_{2}, ..., *x*_{*n*}$ ($1 ≤ *x*_{1} < *x*_{2} < ... < *x*_{*n*} ≤ 10^{9}$).

翻译中…

The third line contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{1}, *a*_{2}, ..., *a*_{*n*} ≤ 10^{9}$).

翻译中…

The fourth line contains $*n*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$ ($1 ≤ *b*_{1}, *b*_{2}, ..., *b*_{*n*} ≤ 10^{9}$).

翻译中…

The fifth line contains $*n*$ integers $*c*_{1}, *c*_{2}, ..., *c*_{*n*}$ ($1 ≤ *c*_{1}, *c*_{2}, ..., *c*_{*n*} ≤ 10^{9}$).

翻译中…

The sixth line contains $*n*$ integers $*d*_{1}, *d*_{2}, ..., *d*_{*n*}$ ($1 ≤ *d*_{1}, *d*_{2}, ..., *d*_{*n*} ≤ 10^{9}$).

翻译中…

Output

翻译中…

Print the minimum amount of time Scott needs to get to the Cross while visiting each chair exactly once.

翻译中…

Note

翻译中…

In the sample testcase, an optimal solution would be image. Spent time would be $17 + 24 + 23 + 20 + 33 + 22 = 139$.

翻译中…

样例

Input #1
7 4 3
8 11 12 16 17 18 20
17 16 20 2 20 5 13
17 8 8 16 12 15 13
12 4 16 4 15 7 6
8 14 2 11 17 12 8
Output #1
139
InputCopy OutputCopy
题目信息
题号
704B
时间限制
4 s
内存限制
256 MB
标签
动态规划
图论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。