Problem p03032 (python)

Fixed submission:
N, K = map(int, input().strip().split())
V = list(map(int, input().strip().split()))
H = []
maxi = 0
for i in range(min(N, K)):
    for o in range(i+2):  # error1
        ts = 0
        hand = []
        for p in range(o):
            hand.append(V[p])
        for p in range(N-(i-o)-1, N):  # error2
            hand.append(V[p])
        for values in hand:
            ts += values
        if ts > maxi:
            maxi = ts
        if len(hand) > 0:
            hand.sort()
            for j in range(K-i-1):  # error3
                if len(hand) > 0:
                    if hand[0] < 0:
                        del hand[0]
                    else:
                        break
        ts = 0
        for k in hand:
            ts += k
        if ts > maxi:
            maxi = ts
print(maxi)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().strip().split())
V = list(map(int, input().strip().split()))
H = []

maxi = 0
for i in range(N):
    for o in range(i):
        fs = 0
        bs = 0
        hand = []
        for p in range(o):
            fs += V[p]
            hand.append(V[p])
        for p in range(i-o, N):
            bs += V[p]
            hand.append(V[p])
        ts = fs + bs
        if ts > maxi:
            maxi = ts
        if len(hand) > 0:
            hand.sort()
            for j in range(K-i):
                if hand[0] <= 0:
                    del hand[0]
                else:
                    break
        ts = 0
        for k in hand:
            ts += k
        if ts > maxi:
            maxi = ts
print(maxi)

Buggy submission (verdict: Runtime Error):
maxi = 0
for i in range(N):
    for o in range(i):
        fs = 0
        bs = 0
        hand = []
        for p in range(o):
            fs += V[p]
            hand.append(V[p])
        for p in range(i-o, N):
            bs += V[p]
            hand.append(V[p])
        ts = fs + bs
        if ts > maxi:
            maxi = ts
        if len(hand) > 0:
            hand.sort()
        for j in range(K-i):
            if hand[0] <= 0:
                del hand[0]
        ts = 0
        for k in hand:
            ts += k
        if ts > maxi:
            maxi = ts
print(maxi)

Buggy submission (verdict: Runtime Error):
maximum = 0
for u in range(K):
    for i in u:
        frontSum = 0
        frontList = []
        backSum = 0
        backList = []
        for o in range(i):
            frontSum += V[o]
            frontList.append(V[o])
        for o in range(len(V)-(K-i), len(V)):
            backSum += V[o]
            backList.append(V[o])
        total = frontSum + backSum
        if total > maximum:
            maximum = total
        frontList.sort()
        backList.sort()
        for p in range(K-u):
            frontList = frontLIst[p:]
            newFrontSum = 0
            for k in frontList:
                newFrontSum += k
            if newFrontSum > frontSum:
                frontSum = newFrontSum
            for j in range(K-u-p):
                backList = backList[p:]
                newBackSum = 0
                for k in backList:
                    nweBackSum += k
                if newBackSum > backSum:
                    backSum = newBackSum
        newTotal = backSum + frontSum
        if newTotal > maximum:
            maximum = newTotal
print(maximum)

Buggy submission (verdict: Runtime Error):
maximum = float("-inf")
for i in range(K):  # gets the sum of first i numbers + last K-i numbers
    frontSum = 0
    frontList = []
    backSum = 0
    backList = []
    for o in range(i):
        frontSum += V[o]
        frontList.append(V[o])
    for o in range(len(V)-(K-i), len(V)):
        backSum += V[o]
        backList.append(V[o])
    total = frontSum + backSum
    if total > maximum:
        maximum = total
    frontList.sort()
    backList.sort()
    for p in range(2, len(frontList), 2):
        for j in range(p):
            frontList = frontList[p:]
            newFrontSum = 0
            for k in frontList:
                newFrontSum += k
            if newFrontSum > frontSum:
                frontSum = newFrontSum
    for p in range(2, len(backList), 2):
        for j in range(p):
            backList = backList[p:]
            newBackSum = 0
            for k in backList:
                newBackSum += k
            if newBackSum > backSum:
                backSum = newBackSum
    newTotal = backSum + frontSum
    if newTotal > maximum:
        maximum = newTotal
print(maximum)

Buggy submission (verdict: Runtime Error):
maximum = float("-inf")
for i in range(K): # gets the sum of first i numbers + last K-i numbers
    frontSum = 0
    frontList = []
    backSum = 0
    backList = []
    for o in range(i):
        frontSum += V[o]
        frontList.append(V[o])
    for o in range(len(V)-(K-i-1), len(V)):
        backSum += V[o]
        backList.append(V[o])
    total = frontSum + backSum
    if total > maximum:
        maximum = total
    frontList.sort()
    backList.sort()
    for p in range(2, i, 2):
        for j in range(p):
            frontList = frontList[p:]
            newFrontSum = 0
            for k in frontList:
                newFrontSum += k
            if newFrontSum > frontSum:
                frontSum = newFrontSum
    for p in range(2, K-i, 2):
        for j in range(p):
            backList = backList[p:]
            newBackSum = 0
            for k in backList:
                newBackSum += k
            if newBackSum > backSum:
                backSum = newBackSum
    newTotal = backSum + frontSum
    if newTotal > maximum:
        maximum = newTotal
print(maximum)