Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
X = list(map(int, input().split()))

sorted_X = sorted(X, key=abs)

centers = []

if sorted_X[0] == 0:
    # 0がある場合
    centers.append(X.index(0))
else:
    for x in sorted_X:
        if x > 0:
            centers.append(X.index(x))
            break

    for x in sorted_X:
        if x < 0:
            centers.append(X.index(x))
            break


edge_pairs = []
# ひだりエッジ
for center_index in centers:
    left_edge = center_index - (K - 1)
    if left_edge >= 0:
        start_left_edge_index = left_edge
        start_right_edge_index = center_index
    else:
        start_left_edge_index = 0
        start_right_edge_index = K-1

    for move in range(K):
        left_edge = start_left_edge_index + move
        right_edge = start_right_edge_index + move
        if right_edge >= N:
            break
        edge_pairs.append((left_edge, right_edge))
edge_pairs = list(set(edge_pairs))


propose = []
for (left, right) in edge_pairs:
    pos_max = 0
    neg_max = 0
    for i in range(left, right+1):
        target = X[i]
        if target > 0:
            if pos_max < target:
                pos_max = target

        if target < 0:
            if neg_max < abs(target):
                neg_max = abs(target)

    propose.append(pos_max + 2 * neg_max)
    propose.append(neg_max + 2 * pos_max)


print(min(propose))





Fixed submission:
N, K = map(int, input().split())
X = list(map(int, input().split()))

sorted_X = sorted(X, key=abs)

centers = []

if sorted_X[0] == 0:
    # 0がある場合
    centers.append(X.index(0))
else:
    for x in sorted_X:
        if x > 0:
            centers.append(X.index(x))
            break

    for x in sorted_X:
        if x < 0:
            centers.append(X.index(x))
            break


#edge_pairs = []
lefts = []
# ひだりエッジ
for center_index in centers:
    left_edge = center_index - (K - 1)
    if left_edge >= 0:
        start_left_edge_index = left_edge
        start_right_edge_index = center_index
    else:
        start_left_edge_index = 0
        start_right_edge_index = K-1

    for move in range(K):
        left_edge = start_left_edge_index + move
        right_edge = start_right_edge_index + move
        if right_edge >= N:
            break
        #edge_pairs.append((left_edge, right_edge))
        lefts.append(left_edge)
lefts = list(set(lefts))

start_left = min(lefts)
search_num = len(lefts)

pos_max = 0
neg_max = 0

propose = []
for i in range(start_left, start_left + K):
    target = X[i]
    if target > 0:
        if pos_max < target:
            pos_max = target

    if target < 0:
        if neg_max < abs(target):
            neg_max = abs(target)

propose.append(pos_max + 2 * neg_max)
propose.append(neg_max + 2 * pos_max)


for slide in range(search_num-1):
    start_left += 1
    left = start_left
    right = start_left + K - 1

    left_target = X[left]
    if left_target < 0:
        neg_max = abs(left_target)
    elif target == 0:
        neg_max = 0

    right_target = X[right]
    if right_target > 0:
        pos_max = right_target
    elif right_target == 0:
        pos_max = 0

    propose.append(pos_max + 2 * neg_max)
    propose.append(neg_max + 2 * pos_max)


print(min(propose))