TnT/Multi_CodeNet4Repair huggingface dataset:
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):
n, k= map(int,input().split())
x = list(map(int, input().split()))
if 0 not in x:
    k += 1
    x.append(0)
    x = sorted(x)
x = [abs(i) for i in x]

orig = x.index(0)

ans = float("inf")
for i in range(k):
    f = orig + i
    s = orig + i - k
    if (s >= 0) and (f <= n-1):
        temp1 = x[s]
        temp2 = x[f]
        ans = min([ans, 2*temp1+temp2, temp1+2*temp2])

print(ans)

n, k= map(int,input().split())
x = list(map(int, input().split()))
if 0 not in x:
    k += 1
    x.append(0)
    x = sorted(x)
x = [abs(i) for i in x]

orig = x.index(0)

ans = float("inf")
for i in range(k):
    f = orig + i
    s = orig + i - k + 1
    if (s >= 0) and (f <= len(x)-1):
        temp1 = x[s]
        temp2 = x[f]
        ans = min([ans, 2*temp1+temp2, temp1+2*temp2])

print(ans)

Verdicts: Wrong Answer

Accepted
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):
N, K = map(int, input().split())
x = list(map(int, input().split()))

point= len(x) - 1
for i, v in enumerate(x):
    if v >= 0:
        point = i
        break

start = max(0, point - K + 1)
end = start + K - 1

if x[point] != 0:
    start -= 1
    end -= 1
    
ans = float('inf')

while True:
    if x[start] >= 0:
        time = x[end]
    elif x[end] <= 0:
        time = abs(x[start])
    elif abs(x[start]) <= x[end]:
        time = abs(x[start] * 2) + x[end]
    else:
        time = abs(x[start]) + (x[end] * 2)
    ans = min(ans, time)
    
    start += 1
    end += 1

    if start > point or end == len(x):
        break
    
print(ans)

N, K = map(int, input().split())
x = list(map(int, input().split()))

point= len(x) - 1
for i, v in enumerate(x):
    if v == 0:
        point = i
        break
    elif v > 0:
        point = i - 1
        break

start = max(0, point - K + 1)
end = start + K - 1

if x[point] != 0:
    point += 1
    
ans = float('inf')

while True:
    if x[start] >= 0:
        time = x[end]
    elif x[end] <= 0:
        time = abs(x[start])
    elif abs(x[start]) <= x[end]:
        time = abs(x[start] * 2) + x[end]
    else:
        time = abs(x[start]) + (x[end] * 2)
    ans = min(ans, time)
    
    start += 1
    end += 1

    if start > point or end == len(x):
        break
    
print(ans)

Verdicts: Wrong Answer

Accepted
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):
n, k = map(int, input().split())
X = list(map(int, input().split()))

for i in range(n):
  if X[i] > 0:
    over_zero = i
    break
else:
  over_zero = n

min_cost = 10**8

if over_zero + k - 1 < n:
  min_cost = X[over_zero + k - 1]

if over_zero - k >= 0:
  min_cost = min(X[over_zero - k], min_cost)
for i in range(0, k+1):
  
  if over_zero - i >= 0:
    minus_cost = -(X[over_zero - i])
  else:
    continue
  
  if over_zero + k - i - 1 < n:
    plus_cost = (X[over_zero + k - i - 1])
  else:
    continue
  cost = plus_cost + minus_cost + min(plus_cost, minus_cost) 
  min_cost = min(cost, min_cost)

print(min_cost)


n,k=map(int,input().split())
x=sorted(list(map(int,input().split())))
print(min((min(abs(x[i])+abs(x[i+k-1]-x[i]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]))) for i in range(n-k+1)))

Verdicts: Runtime Error

Accepted
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):
N, K = map(int, input().split())
X = map(int, input().split())

k = []
# print(X)

k0 = abs(X[0])
for n in range(0+1, K):
    k0 += X[n] - X[n-1]
# print(k0)
k.append(k0)
for i in range(1, len(X)-K+1):
    # print(i, i-1, i+K, i+K-1)
    ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])
    k.append(ki)
print(min(k))


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

k = []
# print(X)

k0 = abs(X[0])
for n in range(0+1, K):
    k0 += X[n] - X[n-1]
k.append(k0)
for i in range(1, len(X)-K+1):
    ki = k[i-1] - (X[i] - X[i-1]) + (X[i+K-1] - X[i+K-2]) - abs(X[i-1]) + abs(X[i])
    k.append(ki)
# print(min(k))

l = []
l0 = abs(X[N-1])
for n in range(N-1, N-K, -1):
    l0 += X[n] - X[n-1]
# print(l0)
l.append(l0)
for i in range(1, len(X)-K+1):
    # print(i, i-1, i+K, i+K-1)
    li = l[i-1] - (X[N-i] - X[N-i-1]) + (X[N-K-i+1] - X[N-K-i]) - abs(X[N-i]) + abs(X[N-i-1])
    # print(li)
    l.append(li)
print(min(min(k), min(l)))


Verdicts: Runtime Error

Accepted
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):
n, k = map(int, input().split())
x = list(map(int, input().split()))
p = n
for i in range(n):
  if x[i] > 0:
    p = i
    break
result = float('inf')
for i in range(max(p - k, 0), min(k - p, k + 1)):
  if i == 0:
    result = min(result, x[p + k - 1])
  elif i == k:
    result = min(result, -x[p - k])
  else:
    l = x[p - i]
    r = x[p + (k - i) - 1]
    result = min(result, r - 2 * l, r * 2 - l)
print(result)


n, k = map(int, input().split())
x = list(map(int, input().split()))
p = n
for i in range(n):
  if x[i] > 0:
    p = i
    break
result = float('inf')
for i in range(k + 1):
  if p - i < 0 or p + k - i > n:
    continue
  if i == 0:
    result = min(result, x[p + k - 1])
  elif i == k:
    result = min(result, -x[p - k])
  else:
    l = x[p - i]
    r = x[p + (k - i) - 1]
    result = min(result, r - 2 * l, r * 2 - l)
print(result)


Verdicts: Runtime Error

Accepted
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):
import numpy as np
import bisect
N,K=map(int,input().split())
X=[int(i) for i in input().split()]
min_=10**10
for i in range(N-K+1):
    if X[i] == 0 or X[i+K-1] == 0:
        print(max(abs(X[i]),abs(X[i+K-1])))
        min_=min(min_,max(abs(X[i]),abs(X[i+K-1])))
    elif np.sign(X[i]) == np.sign(X[i+K-1]):
        print(max(abs(X[i]),abs(X[i+K-1])))
        min_=min(min_,max(abs(X[i]),abs(X[i+K-1])))
    else:
        print(abs(min(X[i],X[i+K-1]))*2+abs(max(X[i],X[i+K-1])))
        min_=min(min_,abs(min(X[i],X[i+K-1]))*2+abs(max(X[i],X[i+K-1])))
print(min_)

import numpy as np
import bisect
N,K=map(int,input().split())
X=[int(i) for i in input().split()]
min_=10**10
for i in range(N-K+1):
    #print(i,i+K-1)
    temp=min(abs(X[i])+abs(X[i]-X[i+K-1]),abs(X[i+K-1])+abs(X[i]-X[i+K-1]))
    min_=min(temp,min_)
print(min_)

Verdicts: Wrong Answer

Accepted
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):
import bisect

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

if 0 in X:
  K=K-1

Right=[]
Left=[]
  
for x in X:
  if x>0:
    Right.append(x):
  else:
    Left=[abs(x)]+Left

print(Right)
print(Left)
      
    

import bisect

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

if 0 in X:
  K=K-1
ans=[]
Right=[]
Left=[]
  
for x in X:
  if x>0:
    Right.append(x)
  else:
    Left.append(abs(x))

Left.append(0)
Left.sort()
Right=[0]+Right
    
for i in range(K+1):
  if i<=len(Right)-1 and K-i<=len(Left)-1:
    ans.append(min(Right[i],Left[K-i])*2+max(Right[i],Left[K-i]))

if K==0:
  ans.append(0)

print(min(ans))


Verdicts: Runtime Error

Accepted
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):
import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
if (x[0]<0) and (x[-1]>0):
  pls = x[p:]
  mns = x[:m]
  ans = math.inf

  for i in range(len(pls)):
    if i < K-1:
      if pls[0] == 0:
        n = K - i
      else:
        n = K - i - 1
      if len(mns) >= n:
        tmp = 2*abs(mns[-n]) + pls[i]
        ans = min(ans, tmp)
    if i == K-1:
      ans = min(ans, pls[i])
      break
    
  for i in range(len(mns)):
    m = len(mns)-i
    if m < K:
      if pls[0] == 0:
        n = K - m
      else:
        n = K - m - 1
      if len(pls) > n:
        tmp = 2*pls[n] + abs(mns[-m])
        print(i, tmp)
        ans = min(ans, tmp)
    if m == K:
      ans = min(ans, abs(mns[i]))
    
elif x[0] >= 0:
  ans = x[K-1]
  
else:
  ans = abs(x[-K])
  
print(ans)

import math
N, K = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
  if x[i] == 0:
    p, m = i, i+1
    break
  elif x[i] > 0:
    p, m = i, i
    break
    
if (x[0]<0) and (x[-1]>0):
  pls = x[p:]
  mns = x[:m]
  ans = math.inf

  for i in range(len(pls)):
    if i < K-1:
      if pls[0] == 0:
        n = K - i
      else:
        n = K - i - 1
      if len(mns) >= n:
        tmp = 2*abs(mns[-n]) + pls[i]
        ans = min(ans, tmp)
    if i == K-1:
      ans = min(ans, pls[i])
      break
    
  for i in range(len(mns)):
    m = len(mns)-i
    if m < K:
      if pls[0] == 0:
        n = K - m
      else:
        n = K - m - 1
      if len(pls) > n:
        tmp = 2*pls[n] + abs(mns[-m])
        ans = min(ans, tmp)
    if m == K:
      ans = min(ans, abs(mns[i]))
    
elif x[0] >= 0:
  ans = x[K-1]
  
else:
  ans = abs(x[-K])
  
print(ans)

Verdicts: Wrong Answer

Accepted
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):
n, k = map(int, input().split())
X = list(map(int, input().split()))

count_0 = X.count(0)

if k <= count_0:
    print(0)
    exit()

k -= count_0

neg = [x for x in X if x < 0]
pos = [x for x in X if x > 0]

neg_count = len(neg)
pos_count = len(pos)

if not neg:
    print(pos[k-1])
    exit()
if not pos:
  	print(neg[-k])
    exit()

res = []
for left in range(1, min(neg_count, k)):
    time1 = neg[-left]
    right = k - left - 1
    if right >= pos_count:
        continue
    elif right < 0:
        res.append(abs(time1))
    else:
        time2 = pos[right]
        res.append(time2-time1*2)

for right in range(min(pos_count, k)):
    time1 = pos[right]
    left = k - right - 1
    if left >= neg_count:
        continue
    elif left <= 0:
        res.append(abs(time1))
    else:
        time2 = neg[-left]
        res.append(time1*2-time2)


print(min(res))

n, k = map(int, input().split())
X = list(map(int, input().split()))

count_0 = X.count(0)

if k <= count_0:
    print(0)
    exit()

k -= count_0

neg = [x for x in X if x < 0]
pos = [x for x in X if x > 0]

neg_count = len(neg)
pos_count = len(pos)

if not neg:
    print(pos[k-1])
    exit()

res = []
for left in range(1, min(neg_count, k)):
    time1 = neg[-left]
    right = k - left - 1
    if right >= pos_count:
        continue
    elif right < 0:
        res.append(abs(time1))
    else:
        time2 = pos[right]
        res.append(time2-time1*2)

for right in range(min(pos_count, k)):
    time1 = pos[right]
    left = k - right - 1
    if left >= neg_count:
        continue
    elif left <= 0:
        res.append(abs(time1))
    else:
        time2 = neg[-left]
        res.append(time1*2-time2)


n, k = map(int, input().split())
X = list(map(int, input().split()))

ans = []
for i in range(n-k+1):
    left = X[i]
    right = X[i+k-1]
    if left * right < 0:
        result = min(abs(left), abs(right)) * 2 + max(abs(left), abs(right))
    else:
        result = max(abs(left), abs(right))
    ans.append(result)

print(min(ans))

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
n,k=map(int,input().split())
candle=list(map(int,input().split()))
com=list(itertools.product(["1","0"], repeat=n))
ans=2000000000
for i in range(n-k):
  if candle[i]<0 and candle[i+k-1]>0:
    temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])
  else:
    temp=abs(candle[i+k-1]-candle[i])
  ans=min(temp, ans)
print(ans)

import itertools
import collections
n,k=map(int,input().split())
candle=list(map(int,input().split()))
com=list(itertools.product([1,0], repeat=n))
ans=200000000
for i in range(2**n):
  count=collections.Counter(com[i])
  if count[1]==k:
    begin=0
    end=0
    cnt=0
    temp=0
    print(
    for j in range(n):
      if com[i][j]==1:
        cnt+=1
        if cnt==1:
          start=candle[j]
        elif cnt==k:
          end=candle[j]
          break;
    if start>=0:
      temp=abs(end)
      if temp<ans:
        ans=temp
    if end<=0:
      temp=abs(start)
      if temp<ans:
        ans=temp
    else:
      temp=min(abs(start), end)*2+max(abs(start), end)
      if temp<ans:
        ans=temp
print(ans)

n,k=map(int,input().split())
candle=list(map(int,input().split()))
ans=2000000000
for i in range(n-k+1):
  if candle[i]<0 and candle[i+k-1]>0:
    temp=min(abs(candle[i]), candle[i+k-1])*2+max(abs(candle[i]), candle[i+k-1])
  elif candle[i+k-1]<=0:
    temp=abs(candle[i])
  elif candle[i]>=0:
    temp=candle[i+k-1]
  ans=min(temp, ans)
print(ans)

Verdicts: Runtime Error

Runtime Error

Accepted
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):
N, K=map(int, input().split())
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(N-K+1):
    temp1 = abs(x[i]) + abs(x[i]-x[i+K-1])
    #temp2 = abs(x[i+K-1]) + abs(x[i]-x[i+K-1])
    ans = min(ans, temp1, temp2)
print(ans)


N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = pow(10, 10)
for i in range(K, len(x)):
  ans = min(ans, abs(x[i-1]) + abs(x[i-1] - x[i-K]))
print(ans)

N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = 10 ** 9
for i in range(len(a) - K + 1):
  l = a[i]
  r = a[i + K - 1]
  ans = min(ans, abs(l) + abs(r - l), abs(r) + abs(l - r))
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
n,k = (int(_) for _ in input().split())
x = [int(_) for _ in input().split()]


#!/usr/bin/env python3
import sys


def solve(N: int, K: int, x: "List[int]"):

    ans = 10000000000000000000


    al = []

    for i in range(N-K+1):
        if(x[i] <= 0 <= x[i+K-1]):
            w = abs(x[i+K-1]) + abs(x[i]) + min(abs(x[i+K-1]), abs(x[i]))
        else:
            w = max(abs(x[i+K-1]),abs(x[i]))
        
        al = [x[i], x[i+K-1]]
        ans = min(ans, w)
        
    if(not al):
        print(0)
    else:
        print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, x)

if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
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):
n, k = map(int,input().split())

arr = list(map(int, input().split()))

ans = float('inf')

for i in range(n - k + 1):
	if arr[i] * arr[k + i -1] >= 0:
		tmp = max(abs(arr[i]), abs(arr[k + i -1]))
		print(tmp)
	else:
		tmp = abs(arr[i]) + abs(arr[k + i -1]) + min(abs(arr[i]), abs(arr[k + i -1]))
	ans = min(ans, tmp)

print(ans)
		

n, k = map(int,input().split())

arr = list(map(int, input().split()))

ans = float('inf')

for i in range(n - k + 1):
	if arr[i] * arr[k + i -1] >= 0:
		tmp = max(abs(arr[i]), abs(arr[k + i -1]))
	else:
		tmp = abs(arr[i]) + abs(arr[k + i -1]) + min(abs(arr[i]), abs(arr[k + i -1]))
	ans = min(ans, tmp)

print(ans)
		

Verdicts: Wrong Answer

Accepted
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):
N, K = map(int, input().split())
arr = list(map(int, input().split()))

ans = float('inf')
for i in range(N+1-K):
    print(arr[i],arr[i+K-1])
    if arr[i]<= 0 and arr[i+K-1]>0:
        preans = min(abs(arr[i]*2) + arr[i+K-1], abs(arr[i]) + arr[i+K-1]*2)
    elif arr[i]<=0 and arr[i+K-1]<=0:
        preans = abs(arr[i])
    elif arr[i]>=0 and arr[i+K-1]>=0:
        preans = arr[i+K-1]
    ans = min(ans,preans)

print(ans)

N, K = map(int, input().split())
arr = list(map(int, input().split()))

ans = float('inf')
for i in range(N+1-K):
    if arr[i]<= 0 and arr[i+K-1]>0:
        preans = min(abs(arr[i]*2) + arr[i+K-1], abs(arr[i]) + arr[i+K-1]*2)
    elif arr[i]<=0 and arr[i+K-1]<=0:
        preans = abs(arr[i])
    elif arr[i]>=0 and arr[i+K-1]>=0:
        preans = arr[i+K-1]
    ans = min(ans,preans)

print(ans)

Verdicts: Wrong Answer

Accepted
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):
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9
for i in range(k-1, n):
  dR = abs(x[i]) + abs(x[i] - x[i-k+1])
  dL = abs(x[i-k+1]) + abs(x[i] - x[i-k+1])
  ans = min(ans, dR, dL)
  print(i, dR, dL)
print(ans)

n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9
for i in range(k-1, n):
  dR = abs(x[i]) + abs(x[i] - x[i-k+1])
  dL = abs(x[i-k+1]) + abs(x[i] - x[i-k+1])
  ans = min(ans, dR, dL)
print(ans)

Verdicts: Wrong Answer

Accepted
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):
N, K = map(int, input().split())
x_list = list(map(int, input().split()))

result = []
for i in range(N-K):
    start = i
    end = i + K -1
    result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))
    result.append(abs(x_list[end]) +  abs(x_list[end] - x_list[start] ))
print(min(result))

N, K = map(int, input().split())
x_list = list(map(int, input().split()))

result = []
for i in range(N-(K-1)):
    start = i
    end = i + (K -1)
    result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))
    result.append(abs(x_list[end]) +  abs(x_list[end] - x_list[start] ))
print(min(result))

N, K = map(int, input().split())
x_list = list(map(int, input().split()))

result = []
for i in range(N-K):
    start = i
    end = i + K 
    result.append(abs(x_list[start] + abs(x_list[end] - x_list[start])))
    result.append(abs(x_list[end]) +  abs(x_list[end] - x_list[start] ))
print(min(result))

N, K = map(int, input().split())
x_list = list(map(int, input().split()))

if x_list[0] >= 0:
    for i in range(N - K):
        x_list.pop(-1)
    print(max(x_list))

else:
    for i in range(N-K):
        p = abs(x_list[-1] - x_list[-2])
        n = abs(x_list[0] - x_list[1])
        if p > n:
            x_list.pop(-1)
        else:
            x_list.pop(0)
    print(x_list)
    if x_list[0] >= 0:
        print(max(x_list))
    else:
        print(x_list[-1] - x_list[0]*2)

N, K = map(int, input().split())
x_list = list(map(int, input().split()))

result = []
for i in range(N-(K-1)):
    start = i
    end = i + (K -1)
    result.append(abs(x_list[start]) + abs(x_list[end] - x_list[start]))
    result.append(abs(x_list[end]) + abs(x_list[end] - x_list[start]))
print(min(result))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted
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):
N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K = max(K-1, 0) 
print(K)
l = []
for i, candle in enumerate(candles):
  sign = candle > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candle * s)
  else:
    l.append(candle * s + candles[ik] * -2 * s)
if len(l) == 0:
  l.append(0)
l.sort()
print(l[0])

N, K = [int(item) for item in input().split()]
candles = []
for item in input().split():
  if int(item) == 0:
    K -= 1
    continue
  candles.append(int(item))
K = max(K-1, 0) 
print(K)
l = []
for i, candle in enumerate(candles):
  sign = candle > 0
  s = 1 if sign else -1
  ik = i-K if sign else i+K
  if ik > N or ik < 0:
    continue
  if (candles[ik] > 0) == sign:
    l.append(candle * s)
  else:
    l.append(candle * s + candles[ik] * -2 * s)
if len(l) == 0:
  l.append(0)
l.sort()
print(l[0])

N, K = [int(item) for item in input().split()]
candles = [int(item) for item in input().split()]
ans = []
for i in range(N-K+1):
  l, r = i, i+K-1
  ans.append(abs(candles[l]) + abs(candles[l] - candles[r]))
  ans.append(abs(candles[r]) + abs(candles[r] - candles[l]))
ans.sort()
print(ans[0])

Verdicts: Runtime Error

Runtime Error

Accepted
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):
N,K=map(int,input().split(" "))
X=sorted(list(map(int,input().split(" "))))

ans=0
for i in range(N-K+1):
    tans=abs(X[i]-X[i+K])+abs(X[i])

    if i==0 or ans>tans:
        ans=tans
    
print(ans)

N,K=map(int,input().split(" "))
X=sorted(list(map(int,input().split(" "))))

ans=0
for i in range(N-K+1):
    tans=abs(X[0]-X[-1])+abs(X[0])

    if i==0 or ans>tans:
        ans=tans
    
print(ans)

N,K=map(int,input().split(" "))
X=sorted(list(map(int,input().split(" "))))

ans=0
for i in range(N-K+1):
    tans=abs(X[i]-X[i+K-1])+abs(X[i])

    if i==0 or ans>tans:
        ans=tans

for i in range(N-K+1):
    tans=abs(X[i]-X[i+K-1])+abs(X[i+K-1])

    if ans>tans:
        ans=tans

print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
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):



n, k = map(int, input().split())
arr = list(map(int, input().split()))


def lower_bound(arr, n):
    
    left, right = 0, len(arr)
    while left < right:
        mid = (left + right) // 2
        if arr[mid] < n:
            left = mid + 1
        else:
            right = mid
    return right


idx = lower_bound(arr, 0)
print("idx={}".format(idx))
ans = 10 ** 16

for i in range(n - k + 1):
    if i + k < idx:
        print("under zero")
        ans = min(ans, abs(arr[i]))
    elif arr[i] < 0 and idx <= i + k:
        print("between zero")
        ans = min(
            ans, 2 * abs(arr[i]) + arr[i + k - 1], abs(arr[i]) + 2 * arr[i + k - 1]
        )
    else:
        print("upper zero")
        ans = min(ans, abs(arr[i + k - 1]))

print(ans)




n, k = map(int, input().split())
arr = list(map(int, input().split()))
ans = 10 ** 10
for i in range(n - k + 1):
    if arr[i] < 0 and arr[i + k - 1] < 0:
        ans = min(ans, abs(arr[i]))
    elif arr[i] < 0 and 0 <= arr[i + k - 1]:
        ans = min(
            ans, abs(arr[i]) * 2 + arr[i + k - 1], abs(arr[i]) + arr[i + k - 1] * 2
        )
    elif 0 <= arr[i] <= arr[i + k - 1]:
        ans = min(ans, arr[i + k - 1])

    # print("taken from {}, ans = {}".format(arr[i : i + k], ans))
print(ans)


Verdicts: Wrong Answer

Accepted
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):
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    if K - i > len(a2):
        continue
    c1 = min(c1, v + a2[K - i])

b = []
b2 = []
for i in x:
    if i > 0:
        b2.append(2 * abs(i))
    else:
        b.append(-i)
b = sorted(b)

if len(b2) == 0:
    print(b[K-1])
    exit()

c2 = float('inf')
for i, v in enumerate(b):
    if K - i > len(b2):
        continue
    c2 = min(c2, v + b2[K - i])

print(min(c1,c2))

N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    if K - i >= len(a2):
        continue
    c1 = min(c1, v + a2[K - i])

b = []
b2 = []
for i in x:
    if i > 0:
        b2.append(2 * abs(i))
    else:
        b.append(-i)
b = sorted(b)

if len(b2) == 0:
    print(b[K-1])
    exit()

c2 = float('inf')
for i, v in enumerate(b):
    if K - i >= len(b2):
        continue
    c2 = min(c2, v + b2[K - i])

print(min(c1,c2))

N, K = map(int, input().split())
x = [int(i) for i in input().split()]
a = []
a2 = []
for i in x:
    if i < 0:
        a2.append(2 * abs(i))
    else:
        a.append(i)

if len(a2) == 0:
    print(a[K-1])
    exit()
a2 = sorted(a2)
c1 = float('inf')

for i, v in enumerate(a):
    if K - i >= len(a2):
        break
    c1 = min(c1, v + a2[K - i])

b = []
b2 = []
for i in x:
    if i > 0:
        b2.append(2 * abs(i))
    else:
        b.append(-i)
b = sorted(b)

if len(b2) == 0:
    print(b[K-1])
    exit()

c2 = float('inf')
for i, v in enumerate(b):
    if K - i >= len(b2):
        break
    c2 = min(c2, v + b2[K - i])

print(min(c1,c2))

N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')
for i in range(N-K+1):
    l = x[i]
    r = x[i+K-1]
    a = abs(l) + abs(r - l)
    b = abs(r) + abs(r - l)
    ans = min(a,b,ans)
print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
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):
N,K = map(int,input().split())
x = list(map(int,input().split()))
if K==1 and (0 in x):
    print(0)
else:
    if 0 in x:
        pass
    else:
        K += 1
        counter = 0
        for i in x:
            if i > 0:
                break
            else:
                counter += 1
        x.insert(counter,0)

    result = []
    g,s = x.index(0),x.index(0)-K+1
    while (not s>x.index(0)):
        if s<0 or g>(len(x)-1):
            s += 1
            g += 1
            continue
        else:
            result.append(2*(-x[s]) + x[g])
            result.append(-x[s] + 2*(x[g]))
            s += 1
            g += 1
    print(result.sort()[0])

N,K = map(int,input().split())
x = list(map(int,input().split()))

result = []
for i in range(N-K+1):
    s,g = i,i+K-1
    result.append(abs(x[s]) + abs(x[s] - x[g]))
    result.append(abs(x[g]) + abs(x[g] - x[s]))
result.sort()
print(result[0])

Verdicts: Runtime Error

Accepted
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):
N, K = map(int,input().split())
x = list(map(int,input().split()))

o = 0
if x[N-1] <= 0:
	print(x[N-K])
	exit()
if x[0] >= 0:
	print(x[K-1])
	exit()
if 0 in x:
	i = x.index(0)
	del x[i]
	N,K = N-1,K=1

while x[o] < 0:
	o += 1
	if o == N-1:
		break

MIN = float("inf")
for i in range(-K-1,K+1,1):
	l = o - i+1
	r = o + K-i
	if not(l < 0 or l >= N or r < 0 or r >= N):
		cur1 = 2* abs(x[l]) + abs(x[r])
#		print([l,r,cur1,cur2])
		if cur1 < MIN:
			MIN = cur1
		if cur2 < MIN:
			MIN = cur2
print(MIN)





N, K = map(int,input().split())
x = list(map(int,input().split()))

MIN = float("inf")
for i in range(N-K+1):
	l = i
	r = i + K - 1
		cur1 = 2*abs(x[l]) + abs(x[r]-x[l])
		cur2 = abs(x[l]) + 2*abs(x[r]-x[l])
#		print([l,r,cur1,cur2])
		if cur1 < MIN:
			MIN = cur1
		if cur2 < MIN:
			MIN = cur2
print(MIN)





#N, K = map(int,input().split())
#x = list(map(int,input().split()))

o = 0
if x[N-1] < 0:
	print(x[N-K])
	exit()
if x[0] > 0:
	print(x[K-1])
	exit()

while x[o] < 0:
	o += 1
	if o == N-1:
		break

MIN = float("inf")
for i in range(-K-1,K+1,1):
	l = o - i+1
	r = o + K-i
	if not(l < 0 or l >= N or r < 0 or r >= N):
		cur1 = 2* abs(x[l]) + abs(x[r])
		cur2 = abs(x[l]) + 2*abs(x[r])
#		print([l,r,cur1,cur2])
		if cur1 < MIN:
			MIN = cur1
		if cur2 < MIN:
			MIN = cur2
print(MIN)





N, K = map(int,input().split())
x = list(map(int,input().split()))

o = 0
if x[N-1] <= 0:
	print(x[N-K])
	exit()
if x[0] >= 0:
	print(x[K-1])
	exit()

MIN = float("inf")
for i in range(N-K+1):
	l = i
	r = i + K
		cur1 = 2*abs(x[l]) + abs(x[r]-x[l])
		cur2 = abs(x[l]) + 2*abs(x[r]-x[l])
#		print([l,r,cur1,cur2])
		if cur1 < MIN:
			MIN = cur1
		if cur2 < MIN:
			MIN = cur2
print(MIN)





#N, K = map(int,input().split())
#x = list(map(int,input().split()))
#N, K = 5, 3
N,K = 8, 5
x = list(map(int,"-9 -7 -4 -3 1 2 3 4".split()))
inf = float("inf")
origin = 0
if x[N-1] < 0:
	print(x[N-K])
	exit()
if x[0] > 0:
	print(x[K-1])
	exit()

while x[origin] < 0:
	origin += 1
	if origin == N-1:
		break

MIN = float("inf")
for i in range(-K,K+1,1):
	l = origin - i+1
	r = origin + K-i
	if not(l < 0 or l >= N or r < 0 or r >= N):
		cur1 = 2* abs(x[l]) + abs(x[r])
		cur2 = abs(x[l]) + 2*abs(x[r])
#		print([l,r,cur1,cur2])
		if cur1 < MIN:
			MIN = cur1
		if cur2 < MIN:
			MIN = cur2
print(MIN)





N, K = map(int,input().split())
x = list(map(int,input().split()))

MIN = float("inf")
for i in range(N-K+1):
	l = i
	r = i + K - 1
	cur1 = abs(x[l]) + abs(x[r]-x[l])
	cur2 = abs(x[r]) + abs(x[r]-x[l])
#	print([l,r,cur1,cur2])
	if cur1 < MIN:
		MIN = cur1
	if cur2 < MIN:
		MIN = cur2
print(MIN)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
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):
import sys

def main(lines):
  N, K = map(int, lines[0].split())
  a = list(map(int, lines[1].split()))
  ans = 1000000000000
  for i in range(N):
    if i + K - 1 >= N:
      break
    b = a[i]
    c = a[i + K - 1]
    if b < 0 and c >= 0:
      ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))
    else:
      ans = min(ans, min(abs(b), abs(c)))
  print(ans)


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

import sys

def main(lines):
  N, K = map(int, lines[0].split())
  a = list(map(int, lines[1].split()))
  ans = 1000000000000
  for i in range(N):
    if i + K - 1 >= N:
      break
    b = a[i]
    c = a[i + K - 1]
    if b < 0 and c >= 0:
      ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))
    else:
      ans = min(ans, man(abs(b), abs(c)))
  print(ans)


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

import sys

def main(lines):
  N, K = map(int, lines[0].split())
  a = list(map(int, lines[1].split()))
  ans = 1000000000000
  for i in range(N):
    if i + K - 1 >= N:
      break
    b = a[i]
    c = a[i + K - 1]
    if b < 0 and c >= 0:
      ans = min(ans, max(abs(b), abs(c)) + 2*min(abs(b), abs(c)))
    else:
      ans = min(ans, max(abs(b), abs(c)))
  print(ans)


if __name__ == '__main__':
    lines = []
    for l in sys.stdin:
        lines.append(l.rstrip('\r\n'))
    main(lines)

Verdicts: Wrong Answer

Runtime Error

Accepted
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):
N, K = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
pos_i = -1
for i in range(len(x)):
    if x[i] >= 0:
        pos_i = i
        break

min_t = 200000000
if pos_i == -1:
    min_t = -x[-K]
else:
    for i in range(N-K+1):
        if i+K < pos_i:
            min_t = -x[pos_i-K]
        elif pos_i <= i:
            min_t = x[pos_i+K-1]
        else:
            min_t = min(min_t, x[K+i-1]-2*x[i], x[K+i-1]*2-x[i])

print(min_t)

N, K = [int(_) for _ in input().split()]
x = [int(_) for _ in input().split()]
pos_i = -1
for i in range(len(x)):
    if x[i] > 0:
        pos_i = i
        break

min_t = 300000000
if pos_i == -1:
    min_t = -x[-K]
else:
    for i in range(N-K+1):
        if i+K-1 < pos_i:
            min_t = min(min_t, -x[pos_i-K])
        elif pos_i <= i:
            min_t = min(min_t, x[pos_i+K-1])
        else:
            min_t = min(min_t, x[K+i-1]-x[i]*2, x[K+i-1]*2-x[i])

print(min_t)

Verdicts: Wrong Answer

Accepted
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):
N,K=map(int,input().split())
x=sorted(list(map(int,input().split())))

ans=0
for i in range(N-K+1):
  tmp1=abs(x[i])+abs(x[i+K-1]-x[i])
  tmp2=abs(x[i+K-1])+abs(x[i+K-1]-x[i])
  tmp=min(tmp1,tmp2)
  ans=min(tmp,ans)

print(ans)

           

N,K=map(int,input().split())
x=sorted(list(map(int,input().split())))

ans=1000000000
for i in range(N-K+1):
  tmp1=abs(x[i])+abs(x[i+K-1]-x[i])
  tmp2=abs(x[i+K-1])+abs(x[i+K-1]-x[i])
  tmp=min(tmp1,tmp2)
  ans=min(tmp,ans)

print(ans)

           

Verdicts: Wrong Answer

Accepted
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):
n,m=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(n-m+1):
  if l[i]>=0:
    l1.append(l[i+m]-l[i])
  elif l[i]<=0<=l[i+m]:
    l1.append(l[i+m]-l[i]+min(l[i],l[i+m]))
  else:
    l1.append(l[i+m]-l[i])
print(min(l1))    

n,m=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(n-m+1):
  if l[i]>=0:
    l1.append(l[i+m-1])
  elif l[i]<=0<=l[i+m-1]:
    l1.append(l[i+m-1]-l[i]+min(abs(l[i]),abs(l[i+m-1])))
  else:
    l1.append(abs(l[i]))
print(min(l1)) 


Verdicts: Runtime Error

Accepted
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):
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = []
for i in range(N-K+1):
  b.append(min(abs(a[i])+abs(a[i+k-1]-a[i]),abs(a[i+k-1])+abs(a[i+k-1]-a[i])))
print(min(b))
  

N,K = map(int,input().split())
a = list(map(int,input().split()))
b = []
dis = N-K+1
for i in range(dis):
  b.append(min(abs(a[i])+abs(a[i]-a[i+K-1]),abs(a[i+K-1])+abs(a[i+K-1]-a[i])))
print(min(b))
    


Verdicts: Runtime Error

Accepted
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):
n,k=map(int,input().split())
x=list(map(int,input().split()))

st=0
m=3*10**8
for i in range(n-1):
  if x[i]<0 and x[i+1]>=0:
    st=i+1

for i in range(n-k+2):
  mi=x[k+i-1]-x[i]+min(abs(x[k+i-1]),abs(x[i]))
  print(x[k+i-1],x[i],mi)
  if k+i<st or i>st:continue
  if mi <m:m=mi
print(m)

n,k=map(int,input().split())
x=list(map(int,input().split()))

st=0
m=3*10**8
for i in range(n-1):
  if x[i]<0 and x[i+1]>=0:
    st=i+1

for i in range(n-k+1):
  mi=x[k+i-1]-x[i]+min(abs(x[k+i-1]),abs(x[i]))
  print(x[k+i-1],x[i],mi)
  if k+i<st or i>st:continue
  if mi <m:m=mi
print(m)

n,k=map(int,input().split())
x=list(map(int,input().split()))

mt=5*10**8

for i in range(n-k+1):
  mt=min(mt,2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]))

if x[0]>0:mt=min(mt,x[k-1])
elif x[-1]<0:mt=min(mt,abs(x[-1-k+1]))
print(mt)
    
  

Verdicts: Runtime Error

Wrong Answer

Accepted
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):
n,k=map(int,input().split())
x=list(map(int,input().split()))
time=1000000
for i in range(n-k+1):
  l=x[i]
  r=x[i+k-1]
  time=min(time,abs(l)+l-r,abs(r)+l-r)
print(time)
  
      
  


n,k=map(int,input().split())
x=list(map(int,input().split()))
time=float'inf'
for i in range(n-k+1):
  l=x[i]
  r=x[i+k-1]
  time=min(time,abs(l)+r-l,abs(r)+r-l)
print(time)
  
      
  


n,k=map(int,input().split())
x=list(map(int,input().split()))
time=100000000000
for i in range(n-k+1):
  l=x[i]
  r=x[i+k-1]
  time=min(time,abs(l)+r-l,abs(r)+r-l)
print(time)
  
      
  


Verdicts: Wrong Answer

Runtime Error

Accepted
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):
N,K=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in (N-K+1):
    if a[i]<0:
        b.append(-2*a[i]+a[i+K-1])
    else:
        b.append(a[i]+a[i+K-1])
print(min(b))


N,K=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(N-K+1):
    b.append(min(abs(a[i])+abs(a[i+K-1]-a[i]),abs(a[i+K-1])+abs(a[i]-a[i+K-1]))
print(min(b))


N,K=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for i in range(N-K+1):
    b.append(min(abs(a[i])+abs(a[i+K-1]-a[i]),abs(a[i+K-1])+abs(a[i]-a[i+K-1])))
print(min(b))


Verdicts: Runtime Error

Runtime Error

Accepted
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):
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    X = [int(c) for c in input().split()]

    def fullsearch():
        for i in range(N-K):
            l = X[i]
            r = X[i+K-1]
            distance = abs(r - l)
            if abs(l) > abs(r):
                distance += r
            else:
                distance += l
            yield distance

    a = list(fullsearch())
    if not a:
        print(0)
    else:
        print(min(a))


main()

import sys
input = sys.stdin.readline

X = []
K = 0
def fullsearch():
    for l, r in zip(X, X[K-1:]):
        distance = abs(r - l)
        yield distance + abs(r)
        yield distance + abs(l)

def main():
    global X, K
    _, K = map(int, input().split())
    X = list(map(int, input().split()))

    print(min(fullsearch()))

main()

Verdicts: Wrong Answer

Accepted