Problem p03274 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=10**10
for i in range(n-k+1):
    c=min(c,-a[i]+a[i+k-1]\
          +min(abs(a[i]),abs(a[i+k-1])))
print(c)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
Z = min(n-zero,zero,k)
cnt = (10**8)*(10**5)
for i in range(Z):
    if cnt > -2*a[zero-i]+a[zero+k-i-1]:
        cnt = -2*a[zero-i]+a[zero+k-i-1]
    else:
        break
for i in range(Z):
    if cnt > -a[zero-k+i]+2*a[zero+i-1]:
        cnt = -a[zero-k+i]+2*a[zero+i-1]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
Z = min(n-zero,zero,k)
cnt = min(-sum(a[Z-k:zero]),sum(a[zero:zero+Z]))
for i in range(1,k):
    if cnt > -2*a[zero-i]+a[zero+k-i-1]:
        cnt = -2*a[zero-i]+a[zero+k-i-1]
    else:
        break
for i in range(1,k):
    if cnt > -a[zero-k+i]+2*a[zero+i-1]:
        cnt = -a[zero-k+i]+2*a[zero+i-1]
    else:
        break

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = min(-sum(a[zero-k:zero]),sum(a[zero:zero+k+1]))
for i in range(1,k):
    if cnt > -2*a[zero-i]+a[zero+k-i-1]:
        cnt = -2*a[zero-i]+a[zero+k-i-1]
    else:
        break
for i in range(1,k):
    if cnt > -a[zero-k+i]+2*a[zero+k-1]:
        cnt = -a[zero-k+i]+2*a[zero+k-1]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = min(-sum(a[zero-k+1:zero]),sum(a[zero:zero+k+1]))
for i in range(1,k):
    if cnt > -2*a[zero-i]+a[zero+k]:
        cnt = -2*a[zero-i]+a[zero+k]
    else:
        break
for i in range(1,k):
    if cnt > -a[zero-k+i]+2*a[zero+k]:
        cnt = -a[zero-k+i]+2*a[zero+k]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = min(-sum(a[zero-k-1:zero]),sum(a[zero:zero+k+1]))
for i in range(1,k):
    if cnt > -2*a[zero-i]+a[zero+k]:
        cnt = -2*a[zero-i]+a[zero+k]
    else:
        break
for i in range(1,k):
    if cnt > -a[zero-k+i]+2*a[zero+k]:
        cnt = -a[zero-k+i]+2*a[zero+k]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = (10**8)*(10**5)
cnt = min(sum(a[zero:n]),-sum(a[0:zero]))
for i in range(1,zero):
    if cnt > -2*a[zero-i]+a[n-1-i]:
        cnt = -2*a[zero-i]+a[n-1-i]
    else:
        break
for i in range(1,zero):
    if cnt > -a[i]+2*a[zero+i-1]:
        cnt = -a[i]+2*a[zero+i-1]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = (10**8)*(10**5)
cnt = min(sum(a[zero:n]),-sum(a[0:zero]))
for i in range(1,zero):
    if cnt > -2*a[zero-i]+a[n-1-i]:
        cnt = -2*a[zero-i]+a[n-1-i]
    else:
        break
for i in range(1,zero):
    if cnt > -a[i]+2*a[zero+i]:
        cnt = -a[i]+2*a[zero+i]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
zero = bisect.bisect_left(a,0)
cnt = (10**8)*(10**5)
cnt = min(sum(a[zero:n]),-sum(a[0:zero]))
for i in range(1,zero):
    if cnt > -2*a[zero-i]+a[n-i]:
        cnt = -2*a[zero-i]+a[n-i]
    else:
        break
for i in range(1,zero):
    if cnt > -a[i]+2*a[zero+i]:
        cnt = -a[i]+2*a[zero+i]
    else:
        break
print(cnt)

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
a.sort()
zero = bisect.bisect_left(a,0)
for i in range(zero):
    if cnt > -2*sum(a[0:zero])+sum(a[zero:n-zero]):
        cnt = -2*sum(a[0:zero])+sum(a[zero:n-zero])
    else:
        break
for i in range(zero):
    if cnt > -sum(a[0:zero])+2*sum(a[zero:n-zero]):
        cnt = -sum(a[0:zero])+2*sum(a[zero:n-zero])
    else:
        break
print(c)