Peter's Lightsabers

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Peter is a Star Wars nerd, and has N plastic lightsabers with various amounts of strength that he bought to play with his friends. Unfortunately, Peter has no real life friends, and now needs to find something to do with his lightsabers.

Peter decides that he will put his lightsabers on display for all to see. However, Peter is very picky about how this design must look. Specifically, there must be between A and B lightsabers put on display, and any two adjacent lightsabers must have different colors. Since Peter is lazy, he wants to be as efficient as possible with this process, and as such, the lightsabers must be left in the relative order they are originally in.

Peter wants to flex on his friends (wait...), so he wants you find him the maximum sum of strength values for his lightsabers on display.

Input Specification

The first line will contain 3 integers, N (1 \leq N \leq 10^5), A,B (1 \leq A \leq B \leq N).

The next line will contain N integers s_i (-10^9 \leq s_i \leq 10^9), the strength of the i^{th} lightsaber.

The final line will contain N integers c_i (1 \leq c_i \leq N), the colour of the i^{th} lightsaber.

Output Specification

One line, the maximum sum of strength values for Peter's display.

Subtasks

Subtask 1 [10%]

1 \leq N \leq 20

Subtask 2 [20%]

1 \leq N \leq 200

Subtask 3 [30%]

1 \leq N \leq 5000

Subtask 4 [40%]

1 \leq N \leq 100000

A = 1, B = N

Sample Input 1

4 2 3
-1 3 4 -5
1 2 2 3

Sample Output 1

3

Comments

There are no comments at the moment.