Problem p03032 (python)

Fixed submission:
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = list(map(int,stdin.readline().rstrip().split()))

getV_num = min(N, K)

ans = 0

for i in range(getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)

        data = []


        for k in range(leftn):
            data.append(V[k])

        for k in range(rightn):
            data.append(V[N-1-k])

        data.sort()
        for _ in range(sute):
            if data:
                if data[0] < 0:
                    del data[0]
                else:
                    break
            else:
                break

        ans = max(ans, sum(data))

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = list(map(int,stdin.readline().rstrip().split()))

getV_num = min(N, K)

ans = 0

for i in range(getV_num//2+1, getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)

        data = []


        for k in range(leftn):
            data.append(V[k])

        for k in range(rightn):
            data.append(V[N-1-k])

        data.sort()
        for _ in range(sute):
            if data[0] < 0:
                del data[0]
            else:
                break

        ans = max(ans, sum(data))

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = list(map(int,stdin.readline().rstrip().split()))

getV_num = min(N, K)

ans = 0

for i in range(getV_num//2+1, getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)*-1

        #print(leftn, rightn)

        if rightn == 0:
            data = V[:leftn]
        elif leftn == 0:
            data = V[rightn:]
        else:
            data = V[:leftn] + V[rightn:]
        #print(data)

        for _ in range(sute):
            data.sort()
            if data[0] < 0:
                del data[0]

        #print(data)

        ans = max(ans, sum(data))

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10

N, K = [int(x) for x in stdin.readline().rstrip().split()]
V = [list(map(int,stdin.readline().rstrip().split()))]

getV_num = min(N, K)

for i in range(getV_num//2+1, getV_num+1):
    toru = i
    sute = K-i

    #print(toru)
    #print(sute)
    
    for j in range(toru+1):
        leftn = j
        rightn = (toru - j)*-1

        #print(leftn, rightn)

        if rightn == 0:
            data = V[:leftn]
        elif leftn == 0:
            data = V[rightn:]
        else:
            data = V[:leftn] + V[rightn:]
        #print(data)

        for _ in range(sute):
            data.sort()
            if data[0] < 0:
                del data[0]

        #print(data)

        ans = max(ans, sum(data))

print(ans)