#P6621. [省选联考 2020 A 卷] 魔法商店

[省选联考 2020 A 卷] 魔法商店

Description

Lili and Lunlun came to a magic shop. There are nn gifts in the shop, numbered from 11 to nn. Gift ii has charm value cic_i and price viv_i.

They want to buy some gifts, but their requirement is strange. Suppose the set of gifts they buy is S={s1,s2,,sp}(1sin)S=\{s_1,s_2,\dots,s_p\}(1\leq s_i\leq n). They require that for any non-empty subset T={t1,t2,,tq}T=\{t_1,t_2,\dots,t_q\} of SS, the XOR sum of the charm values of all gifts in TT is non-zero, i.e., $c_{t_1} \oplus c_{t_2} \oplus \cdots \oplus c_{t_q} \neq 0$. Here, \oplus denotes the XOR operation. On top of this, they also want the number of gifts they buy to be as large as possible.

For example, let c1=1,c2=2,c3=5,c4=6,c5=7c_1=1,c_2=2,c_3=5,c_4=6,c_5=7. Then S1={2,3,5}S_1=\{2,3,5\} does not satisfy the requirement, because c2c3c5=0c_2 \oplus c_3 \oplus c_5=0. Sets S2={1,2,3}S_2=\{1,2,3\} and S3={2,4,5}S_3=\{2,4,5\} satisfy the requirement: every non-empty subset has a non-zero XOR sum. Set S4={1,2}S_4=\{1,2\} is not valid because the number of gifts it contains is not maximal.

There may be many gift sets that satisfy their requirement, so the shop owner picked two such sets AA and BB for them (obviously they contain the same number of gifts). Lunlun likes set AA, but Lili prefers set BB. To make Lili agree to buy set AA, Lunlun decides to use magic to change gift prices. More specifically, Lunlun can spend (xvi)2(x-v_i)^2 magic power to change the price of gift ii to any integer xx. Each gift’s price can be changed at most once.

Lunlun wants that after changing prices, AA is the set with the minimum total price among all gift sets that satisfy the requirement, and BB is the set with the maximum total price among all such gift sets (the total price of a set is the sum of the prices of all gifts it contains). Please help Lunlun compute the minimum magic power he must spend to achieve his goal.

Input Format

The first line contains two integers n,mn, m, representing the total number of gifts and the number of gifts contained in set A(B)A(B), respectively.

The second line contains nn integers cic_i, where the ii-th integer is the charm value of gift ii.

The third line contains nn integers viv_i, where the ii-th integer is the price of gift ii.

The fourth line contains mm integers aia_i, representing the indices of gifts in set AA. The data guarantees that all aia_i are pairwise distinct.

The fifth line contains mm integers bib_i, representing the indices of gifts in set BB. The data guarantees that all bib_i are pairwise distinct.

The data guarantees 1ai,bin1 \leq a_i, b_i \leq n, and both sets AA and BB satisfy their requirement.

Output Format

Output one integer in a single line, representing the minimum magic power Lunlun needs to spend.

5 3
1 2 5 6 7
4 4 2 1 3
1 2 3
2 4 5
6

Hint

Sample 1 Explanation

The valid gift sets are: $\{1,2,3\},\{1,2,4\},\{1,2,5\},\{1,3,4\},\{1,3,5\},\{2,3,4\},\{2,4,5\},\{3,4,5\}$.

One optimal repricing plan is: c1=c2=c4=c5=3c_1=c_2=c_4=c_5=3, c3=2c_3=2.

Sample 2

See the attached files shop2.in and shop2.ans.

Sample 3

See the attached files shop3.in and shop3.ans.

Constraints

For all testdata: 1n10001\leq n\leq 1000, 1m641\leq m\leq 64, 1ci<2641\leq c_i < 2^{64}, 0vi1060\leq v_i\leq 10^6.

The specific limits for each test point are shown in the table below:

Test Point ID nn \leq mm \leq Special Constraint
131 \sim 3 1010 44 1vi51 \leq v_i \leq 5
464 \sim 6 5050 22 1vi101 \leq v_i \leq 10
7107 \sim 10 500500 3030 0vi10 \leq v_i \leq 1
111211 \sim 12 10001000 6464 AA and BB are the same
132013 \sim 20 None

Translated by ChatGPT 5