#abc232f. F - Simple Operations on Sequence

F - Simple Operations on Sequence

Score : 500500 points

问题描述

已知两个包含 NN 个整数的序列:A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N)B=(B1,B2,,BN)B = (B_1, B_2, \ldots, B_N)

在序列 AA 上,你可以按任意顺序执行任意次数(包括零次)以下两种操作:

  • 选择满足 1iN1 \leq i \leq N 的整数 ii,将 AiA_i 增加或减少 11,所需成本为 XX 日元(日本货币)。
  • 选择满足 1iN11 \leq i \leq N-1 的整数 ii,交换 AiA_iAi+1A_{i+1} 的值,所需成本为 YY 日元。

请输出通过重复上述操作使序列 AA 等于序列 BB 所需的最小总成本。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given are two sequences of NN integers each: A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N) and B=(B1,B2,BN)B = (B_1, B_2 \ldots, B_N).

On the sequence AA, you can do the two operations below any number of times (possibly zero) in any order.

  • Choose an integer ii satisfying 1iN1 \leq i \leq N, and increase or decrease AiA_i by 11, for the cost of XX yen (Japanese currency).
  • Choose an integer ii satisfying 1iN11 \leq i \leq N-1, and swap the values of AiA_i and Ai+1A_{i+1}, for the cost of YY yen.

Print the minimum total cost needed to make the sequence AA equal the sequence BB by repeating the above.

Constraints

  • 2N182 \leq N \leq 18
  • 1X1081 \leq X \leq 10^8
  • 1Y10161 \leq Y \leq 10^{16}
  • 1Ai,Bi1081 \leq A_i, B_i \leq 10^8
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN XX YY

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

Output

Print the minimum total cost needed to make AA equal BB.

Sample Input 1

4 3 5
4 2 5 2
6 4 2 1

Sample Output 1

16

Initialy, we have A=(4,2,5,2)A = (4, 2, 5, 2).
The following sequence of operations makes AA equal BB.

  • Pay X=3X = 3 yen to increase the value of A3A_3 by 11, making A=(4,2,6,2)A = (4, 2, 6, 2).
  • Pay Y=5Y = 5 yen to swap the values of A2A_2 and A3A_3, making A=(4,6,2,2)A = (4, 6, 2, 2).
  • Pay Y=5Y = 5 yen to swap the values of A1A_1 and A2A_2, making A=(6,4,2,2)A = (6, 4, 2, 2).
  • Pay X=3X = 3 yen to decrease the value of A4A_4 by 11, making A=(6,4,2,1)A = (6, 4, 2, 1).

The total cost of these operations is 3+5+5+3=163+5+5+3 = 16 yen, which is the minimum possible.

Sample Input 2

5 12345 6789
1 2 3 4 5
1 2 3 4 5

Sample Output 2

0

AA and BB are equal from the beginning, so no operation is needed.

Sample Input 3

18 20719114 5117250357733867
10511029 36397527 63027379 44706927 47672230 79861204 57882493 42931589 51053644 52300688 43971370 26515475 62139996 41282303 34022578 12523039 6696497 64922712
14720753 4621362 25269832 91410838 86751784 32741849 6602693 60719353 28911226 88280613 18745325 80675202 34289776 37849132 99280042 73760634 43897718 40659077

Sample Output 3

13104119429316474

Note that values in input or output may not fit into 3232-bit integer types.

update @ 2024/3/10 10:07:24