#P10156. Minimizing Student Dissatisfaction

    ID: 12145 Type: Default 1000ms 256MiB

Minimizing Student Dissatisfaction

Minimizing Student Dissatisfaction

After the NOIP contest, Little H’s school must decide to send some students back to take cultural courses. In the school there are nn students, and at most mm of them can remain to study information technology. The students form kk different groups (for i=1,2,,ni=1,2,\dots,n, student ii belongs to group cic_i).

You are allowed to choose two students from the same group and send both of them to study cultural courses. If you choose students ii and jj (with ci=cjc_i=c_j) for cultural courses, they will incur a dissatisfaction of $$a_i+a_j+x\times|i-j|$$ (where xx is a constant given at the beginning of the input).

Your task is to force exactly nmn-m students (note that as you always send them in pairs, nmn-m must be even) to take cultural courses (so that at most mm students remain in information technology), while minimizing the total dissatisfaction. If it is impossible to achieve this, output -1.

Note: You must form pairs from within the same group. Each student can be used in at most one pair.

inputFormat

The first line contains three integers nn, mm, and xx.

The second line contains nn integers: a1,a2,,ana_1,a_2,\dots,a_n.

The third line contains nn integers: c1,c2,,cnc_1,c_2,\dots,c_n, where cic_i is the group number of the ii-th student.

outputFormat

Output a single integer — the minimum total dissatisfaction if it is possible to send students in pairs so that at most mm students remain in information technology. Otherwise, output -1.

sample

4 2 1
1 2 3 4
1 1 2 2
4