CF704B.Ant Man

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Scott Lang is at war with Darren Cross. There are nn chairs in a hall where they are, numbered with 1,2,...,n1,2,...,n from left to right. The ii -th chair is located at coordinate xix_{i} . Scott is on chair number ss and Cross is on chair number ee . Scott can jump to all other chairs (not only neighboring chairs). He wants to start at his position (chair number ss ), visit each chair exactly once and end up on chair number ee 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 ii to chair number jj takes xixj|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 ii -th chair takes:

  • cic_{i} extra seconds if he's small.
  • did_{i} extra seconds otherwise (he's large).

Also, landing on ii -th chair takes:

  • bib_{i} extra seconds if he's small.
  • aia_{i} extra seconds otherwise (he's large).

In simpler words, jumping from ii -th chair to jj -th chair takes exactly:

  • xixj+ci+bj|x_{i}-x_{j}|+c_{i}+b_{j} seconds if j<i .
  • xixj+di+aj|x_{i}-x_{j}|+d_{i}+a_{j} seconds otherwise ( j>i ).

Given values of xx , aa , bb , cc , dd find the minimum time Scott can get to Cross, assuming he wants to visit each chair exactly once.

输入格式

The first line of the input contains three integers n,sn,s and ee ( 2n5000,1s,en,se2 \le n \le 5000,1 \le s,e \le n,s≠e ) — the total number of chairs, starting and ending positions of Scott.

The second line contains nn integers x1,x2,...,xnx_{1},x_{2},...,x_{n} ( 1x1<x2<...<xn1091 \le x_{1} < x_{2} < ... < x_{n} \le 10^{9} ).

The third line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1a1,a2,...,an1091 \le a_{1},a_{2},...,a_{n} \le 10^{9} ).

The fourth line contains nn integers b1,b2,...,bnb_{1},b_{2},...,b_{n} ( 1b1,b2,...,bn1091 \le b_{1},b_{2},...,b_{n} \le 10^{9} ).

The fifth line contains nn integers c1,c2,...,cnc_{1},c_{2},...,c_{n} ( 1c1,c2,...,cn1091 \le c_{1},c_{2},...,c_{n} \le 10^{9} ).

The sixth line contains nn integers d1,d2,...,dnd_{1},d_{2},...,d_{n} ( 1d1,d2,...,dn1091 \le d_{1},d_{2},...,d_{n} \le 10^{9} ).

输出格式

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

输入输出样例

  • 输入#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
    

    输出#1

    139
    

说明/提示

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

首页