Problem: There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds.  Initially, no candles are burning. Snuke decides to light K of the N candles.  Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time.  Find the minimum time required to light K candles.

Submission attempts (in order):
class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.x_s = sorted(list(map(int, input().split(" "))))

    def solve(self):
        candidates = []
        for i in range(self.n - self.k + 1):  # 0 .. n-k
            candidates.append((i, i + self.k - 1))

        best_candidate = None
        best_distance = -1
        for c in candidates:
            d = self.distance(c)
            if (best_distance != -1) and (d < best_distance):
                best_candidate = c
                best_distance = d
        # print(best_candidate)
        print(best_distance)

    def distance(self, candidate):
        left = self.x_s[candidate[0]]
        right = self.x_s[candidate[1]]
        # X X X 0
        if right <= 0:
            return abs(left)
        # 0 X X X
        elif left >= 0:
            return abs(right)
        # X 0 X X
        elif abs(left) < abs(right):
            return abs(left) + abs(left) + abs(right)
        # X X 0 X
        else:
            return abs(right) + abs(right) + abs(left)

    def filter(self):
        # Only want -k .. k elements
        right = None
        counter = 0
        for i, v in enumerate(self.x_s):
            if v >= 0:
                counter += 1
                if counter == self.k:
                    right = i + 1
                    break
        if right is None:
            right = len(self.x_s)

        left = None
        counter = 0
        for i, v in reversed(list(enumerate(self.x_s))):
            if v <= 0:
                counter += 1
                if counter == self.k:
                    left = i
                    break
        if left is None:
            left = 0
        return self.x_s[left:right]


if __name__ == "__main__":
    s = Solver()
    s.solve()

class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.x_s = sorted(list(map(int, input().split(" "))))
 
    def solve(self):
        candidates = []
        for i in range(self.n - self.k + 1):  # 0 .. n-k
            candidates.append((i, i + self.k - 1))
            # print(self.x_s[i:i+self.k])
        best_candidate = candidates[0]
        best_distance = self.distance(best_candidate)
        for c in candidates[1:]:
            d = self.distance(c)
            if d < best_distance:
                best_candidate = c
                best_distance = d
        # print(best_candidate)
        print(best_distance)
 
    def distance(self, candidate):
        left = self.x_s[candidate[0]]
        right = self.x_s[candidate[1]]
        # X X X 0
        if right <= 0:
            return abs(left)
        # 0 X X X
        elif left >= 0:
            return abs(right)
        # X 0 X X
        elif abs(left) < abs(right):
            return abs(left) + abs(left) + abs(right)
        # X X 0 X
        else:
            return abs(right) + abs(right) + abs(left)
 
    def filter(self):
        # Only want -k .. k elements
        right = None
        counter = 0
        for i, v in enumerate(self.x_s):
            if v >= 0:
                counter += 1
                if counter == self.k:
                    right = i + 1
                    break
        if right is None:
            right = len(self.x_s)
 
        left = None
        counter = 0
        for i, v in reversed(list(enumerate(self.x_s))):
            if v <= 0:
                counter += 1
                if counter == self.k:
                    left = i
                    break
        if left is None:
            left = 0
        return self.x_s[left:right]
 
 
if __name__ == "__main__":
    s = Solver()
    s.solve()

Verdicts: Wrong Answer

Accepted