문제
According to legend, St. Patrick banished all of the snakes in Mooland over a thousand years ago. However, snakes have since made their way back to Mooland! St. Patrick’s day was on March 17, so Bessie is going to commemorate St. Patrick by banishing all of the snakes from Mooland once and for all.
Bessie is equipped with a net to capture snakes distributed in
A net with size
Please tell Bessie the minimum amount of total wasted space she can accumulate after capturing all the groups.
Problem credits: Patrick Zhang
입력
The first line contains
출력
Output one integer giving the minimum amount of wasted space after Bessie captures all the snakes.
예제1
6 2
7 9 8 2 3 2
3
Bessie’s net starts at a size of 7. After she captures the first group of snakes, she changes her net to a size of 9 and keeps that size until the 4th group of snakes, when she changes her net to size 3. The total wasted space is