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 20kg. The bar starts off empty and must be completely empty when he is done. Sven can squat at most 800kg 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 (1N20, 1K2000), the number of squats Sven must do and the number of pairs of weight plates available.

The second line contains the integers v1,v2,,vN (20vi800), each vi representing that Sven must perform a squat with a bar weighing vi kilograms. These squats must be performed in the order v1, then v2, then v3, .

The third line contains the integers w1,w2,,wK (10wi400), each wi meaning that there are two plates of weight wi. Each wi is a multiple of 10. Formally, wi0 (mod 10) for all i=1,2,,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

K15

2

23

vi500

3

60

No additional constraints.

Explanation of sample 1

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

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

For the third squat, Sven can load 20kg on each side, totalling 20+302+202=120kg.

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
Hide

Please log in to submit a solution to this problem

Log in