Problem p03032 (python)

Fixed submission:
import sys
import collections
import copy


scan = sys.stdin.readline


def main():
    n, k = map(int, scan().rstrip().split())
    values = collections.deque([int(value) for value in scan().rstrip().split()])

    results = []

    for a in range(min(n, k) + 1):
        for b in range(min(n, k) - a + 1):
            hands = [0] * n
            v = copy.deepcopy(values)

            for _ in range(a):
                hands.append(v.popleft())
            for _ in range(b):
                hands.append(v.pop())

            hands.sort()

            c_d = 0
            for c_d in range(k - a - b):
                if hands[c_d] < 0:
                    hands[c_d] = 0
                else:
                    break
            results.append(sum(hands))
            hands = [0] * n

    results.sort(reverse=True)
    print(results[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import collections


scan = sys.stdin.readline


def main():
    n, k = map(int, scan().rstrip().split())
    v = collections.deque([int(value) for value in scan().rstrip().split()])
    hands = [0] * n

    results = []

    for a in range(min(n, k) + 1):
        for b in range(min(n, k) - a + 1):
            for _ in range(a):
                hands.append(v.popleft())
            for _ in range(b):
                hands.append(v.pop())

            hands.sort()

            c_d = 0
            for c_d in range(min(n, k) - a - b):
                if hands[c_d] < 0:
                    hands[c_d] = 0
                else:
                    break
            results.append(sum(hands))
            hands = [0] * n

    results.sort(reverse=True)
    print(results[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import collections


scan = sys.stdin.readline


def main():
    n, k = map(int, scan().rstrip().split())
    v = collections.deque([int(value) for value in scan().rstrip().split()])
    hands = [0] * n

    results = []

    for a in range(min(n, k) + 1):
        for b in range(min(n, k) - a + 1):
            for _ in range(a):
                hands.append(v.popleft())
            for _ in range(b):
                hands.append(v.pop())

            hands.sort()

            c_d = 0
            for c_d in range(k - a - b):
                if hands[c_d] < 0:
                    hands[c_d] = 0
                else:
                    break
            results.append(sum(hands))
            hands = [0] * n

    results.sort(reverse=True)
    print(results[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import collections


scan = sys.stdin.readline


def main():
    n, k = map(int, scan().rstrip().split())
    v = collections.deque([int(value) for value in scan().rstrip().split()])
    hands = [0] * n

    results = []

    for a in range(min(n, k) + 1):
        for b in range(min(n, k) - a + 1):
            for _ in range(a):
                hands.append(v.popleft())
            for _ in range(b):
                hands.append(v.pop())

            hands.sort()

            c_d = 0
            for c_d in range(k - a - b):
                if hands[c_d] < 0:
                    hands[c_d] = 0
                else:
                    break
            print(a, b, c_d)
            results.append(sum(hands))
            hands = [0] * n

    results.sort(reverse=True)
    print(results[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import collections


scan = sys.stdin.readline


def main():
    n, k = map(int, scan().rstrip().split())
    v = collections.deque([int(value) for value in scan().rstrip().split()])
    hands = []

    results = []

    for a in range(min(n, k) + 1):
        for b in range(min(n, k) - a + 1):
            for _ in range(a):
                hands.append(v.popleft())
            for _ in range(b):
                hands.append(v.pop(len(v) - 1))

            hands.sort()

            c_d = 0
            for c_d in range(k - a - b):
                if hands[c_d] < 0:
                    hands[c_d] = 0
                else:
                    break

            results.append(sum(hands))

    results.sort(reverse=True)
    print(results[0])


if __name__ == '__main__':
    main()