#1039
Unrated
JABUKE
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Adrian Satja Kurdija

Mirko has recently discovered an old video game. The screen of this game is divided into N columns. At the bottom of the screen, there is an M-columns-wide boat (M < N). The player can move this boat left or right during the game, but the boat must remain completely within the screen at all times. The boat initially occupies the leftmost M columns. Apples are being dropped from the top of the screen. Each apple starts its fall at the top of one of the N columns, falling straight down until it reaches the bottom of the screen. The next apple starts its fall just after the current one has reached the bottom. An apple is said to be picked up if the boat is placed so that it occupies the column down which the apple is falling when it reaches the bottom. The goal of the game is to pick up all of the apples, in a way that minimizes the distance that the boat must travel.

입력

The first line of input contains two space separated integers N and M (1 ≤ M < N ≤ 10). The second line of input contains an integer J (1 ≤ J ≤ 20), the number of falling apples. The following J lines contain the column positions of those apples, in the order in which they will fall.

출력

The only line of output must contain the minimal distance that the boat must travel in order to pick up all the apples.

예제 입력 1

5 1
3
1
5
3

예제 출력 1

6

예제 입력 2

5 2
3
1
5
3

예제 출력 2

4
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.