#P10156. Minimizing Student Dissatisfaction
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 students, and at most of them can remain to study information technology. The students form different groups (for , student belongs to group ).
You are allowed to choose two students from the same group and send both of them to study cultural courses. If you choose students and (with ) for cultural courses, they will incur a dissatisfaction of $$a_i+a_j+x\times|i-j|$$ (where is a constant given at the beginning of the input).
Your task is to force exactly students (note that as you always send them in pairs, must be even) to take cultural courses (so that at most 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 , , and .
The second line contains integers: .
The third line contains integers: , where is the group number of the -th student.
outputFormat
Output a single integer — the minimum total dissatisfaction if it is possible to send students in pairs so that at most students remain in information technology. Otherwise, output -1.
sample
4 2 1
1 2 3 4
1 1 2 2
4