Hide

Problem F
Gym Aesthetics

The polar bear Sven is competing in the yearly international strongbear competition held in Svalbard. The competition is divided into different events. In the current event, the participants will perform barbell squats with varying weights for each squat.

/problems/gymaesthetics/file/statement/en/img-0001.png
Sven warming up with a barbell

The order of the required weights of the barbell is given beforehand and the participants will have to load and unload weight plates themselves such that they can squat the required weights.

In one move, a participant can either:

  • Add an available weight to each side of the barbell.

  • Remove the outermost weight from each side of the barbell.

Because of his love of aesthetics, Sven wants the weights to be in descending order, meaning that if the innermost weight plate weighs $x$ kilograms, then the next weight plate must be of weight less than or equal to $x$. The first plate can be of any weight.

In order to avoid tiring Sven unnecessarily, we want to calculate the minimum number of moves required for Sven to complete his squats with the required weights in the order given.

The empty barbell (the rod upon which weights are placed) weighs $20$kg. The bar starts off empty and must be completely empty when he is done. Sven can squat at most $800$kg and he does not intend to break this record today. It is guaranteed that there exists a sequence of moves that allows Sven to squat all the required weights in order.

Input

The first line of input contains the integers $N$ and $K$ ($1 \leq N \leq 20$, $1 \leq K \leq 2000$), the number of squats Sven must do and the number of pairs of weight plates available.

The second line contains the integers $v_1, v_2, \dots , v_ N$ ($20 \leq v_ i \leq 800$), each $v_ i$ representing that Sven must perform a squat with a bar weighing $v_ i$ kilograms. These squats must be performed in the order $v_1$, then $v_2$, then $v_3$, $\cdots $.

The third line contains the integers $w_1, w_2, \dots , w_ K$ ($10 \leq w_ i \leq 400$), each $w_ i$ meaning that there are two plates of weight $w_ i$. Each $w_ i$ is a multiple of $10$. Formally, $w_ i \equiv 0\ (\textrm{mod}\ 10)$ for all $i=1,2,\dots ,K$.

Output

Print an integer: the minimum number of moves needed to squat the required weights in the given order.

Points

Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.

Group

Point value

Constraints

$1$

$17$

$K \leq 15$

$2$

$23$

$v_ i \leq 500$

$3$

$60$

No additional constraints.

Explanation of sample 1

For the first squat, the bar already weighs $20$kg. Thus, Sven doesn’t need to do anything.

For the second squat, Sven can load $30$kg on each side of the bar in one move, totalling $20+30+30=80$kg.

For the third squat, Sven can load $20$kg on each side, totalling $20+30\cdot 2+20\cdot 2=120$kg.

Afterwards, he will unload all weights in two moves.

Sample Input 1 Sample Output 1
3 5
20 80 120
20 20 10 30 50
4
Sample Input 2 Sample Output 2
2 3
340 400
150 10 40
6
Sample Input 3 Sample Output 3
1 3
100
20 10 10
6

Please log in to submit a solution to this problem

Log in