Problem p03274 (python)

Fixed submission:
num = input().split(" ")
zahyou = input().split(" ")
zahyou_int = [int(i) for i in zahyou]
num[0] = int(num[0])
num[1] = int(num[1])

rousoku = []
flag = 1
time = 3 * 10 ** 8
for i in range(num[0]-num[1]+1):
    rousoku_min = zahyou_int[i]
    rousoku_max = zahyou_int[(i+num[1]-1)]
    if(flag == 0):
        break
    elif(rousoku_min > 0):
        flag = 0
    time_p = -min(0, rousoku_min) * 2 + rousoku_max
    time_m = max(0, rousoku_max) * 2 - rousoku_min
    if(min(time_p, time_m) < time):
        time = min(time_p, time_m)

print(time)

Buggy submission (verdict: Runtime Error):
num = input().split(" ")
zahyou = input().split(" ")
zahyou_int = []
num[0] = int(num[0])
num[1] = int(num[1])
for i in zahyou:
    zahyou_int.append(int(i))

rousoku = []
time = 4 * 10 ** 8
for i in range(num[0]-num[1]+1):
    if(i == 0 or (zahyou_int[i] <= 0 and zahyou_int[(i+num[1])] >= 0)):
        rousoku = zahyou_int[i:(i+num[1])]
        # print(rousoku)
        time_p = -min(0, min(rousoku)) * 2 + max(rousoku)
        time_m = max(0, max(rousoku)) * 2 - min(rousoku)
        if(min(time_p, time_m) < time):
            time = min(time_p, time_m)

print(time)

Buggy submission (verdict: Runtime Error):
num = input().split(" ")
zahyou = input().split(" ")

num[1] = int(num[1])
plus = []
minus = []
rousoku = []
for i in range(int(num[0])):
    if(int(zahyou[i]) < 0):
        minus.append(int(zahyou[i]))
    else:
        plus.append(int(zahyou[i]))

# プラス方向で終了する場合

if(num[1] > len(plus)):
    plus_tmp = minus[(len(plus)-num[1]):] + plus
    minus_tmp = minus[:(len(minus)+len(plus_tmp)-num[1]-1)]
rousoku = plus_tmp[0:num[1]]
minus_tmp_2 = []
for i in minus_tmp:
    minus_tmp_2.append(i)
while(True):
    if(rousoku[-1] - rousoku[-2] >= (min(min(rousoku), 0) - minus_tmp_2[-1]) * 2):
        rousoku.pop(-1)
        rousoku.insert(0, minus_tmp_2.pop(-1))
    else:
        break
rousoku_move_plus = []
for i in rousoku:
    rousoku_move_plus.append(i - min(rousoku) * 2)

# マイナス方向で終了する場合
if(num[1] > len(minus)):
    minus_tmp = minus + plus[:(num[1]-len(minus))]
    plus_tmp = plus[(num[1]-len(minus)):]
rousoku = minus_tmp[(-(num[1]+1)):]
plus_tmp_2 = []
for i in plus_tmp:
    plus_tmp_2.append(i)
while(True):
    if(rousoku[1] - rousoku[0] >= (plus_tmp_2[0] - max(max(rousoku), 0)) * 2):
        rousoku.pop(0)
        rousoku.append(plus_tmp_2.pop(0))
    else:
        break
rousoku_move_minus = []
for i in rousoku:
    rousoku_move_minus.append(max(rousoku) * 2 - i)

print(min(max(rousoku_move_plus), max(rousoku_move_minus)))

Buggy submission (verdict: Runtime Error):
import copy
num = input().split(" ")
zahyou = input().split(" ")

num[1] = int(num[1])
plus = []
minus = []
rousoku = []
for i in range(int(num[0])):
    if(int(zahyou[i]) < 0):
        minus.append(int(zahyou[i]))
    else:
        plus.append(int(zahyou[i]))

# プラス方向で終了する場合

if(num[1] > len(plus)):
    plus_tmp = minus[(len(plus)-num[1]):] + plus
    minus_tmp = minus[:(len(minus)+len(plus_tmp)-num[1]-1)]
rousoku = plus_tmp[0:num[1]]
minus_tmp_2 = copy.deepcopy(minus_tmp)
while(True):
    if(rousoku[-1] - rousoku[-2] >= (min(min(rousoku), 0) - minus_tmp_2[-1]) * 2):
        rousoku.pop(-1)
        rousoku.insert(0, minus_tmp_2.pop(-1))
    else:
        break
rousoku_move_plus = []
for i in rousoku:
    rousoku_move_plus.append(i - min(rousoku) * 2)

# マイナス方向で終了する場合
if(num[1] > len(minus)):
    minus_tmp = minus + plus[:(num[1]-len(minus))]
    plus_tmp = plus[(num[1]-len(minus)):]
rousoku = minus_tmp[(-(num[1]+1)):]
plus_tmp_2 = copy.deepcopy(plus_tmp)
while(True):
    if(rousoku[1] - rousoku[0] >= (plus_tmp_2[0] - max(max(rousoku), 0)) * 2):
        rousoku.pop(0)
        rousoku.append(plus_tmp_2.pop(0))
    else:
        break
rousoku_move_minus = []
for i in rousoku:
    rousoku_move_minus.append(max(rousoku) * 2 - i)

print(min(max(rousoku_move_plus), max(rousoku_move_minus)))