Problem p03148 (python)

Fixed submission:
#ABC116D-VariousSushi.py

from sys import stdin
#from numpy import sum

input = stdin.readline

N, K = list(map(int, input().split()))
List1= []
kind = set()
point1, point2 = 0, 0

INPUT = [tuple(map(int, input().split())) for _ in range(N)]

INPUT.sort(key = lambda x: -x[1])

for ti, di in INPUT[:K]:
    point1 += di
    if ti in kind:
        List1.append(di)
    kind.add(ti)

point2 = len(kind)

Score = point1 + point2**2
Test = Score

List1POP = List1.pop

for ti, di in INPUT[K:]:
    if 0 >= len(List1):
        break
    if ti in kind:
        continue
    Test = Test - List1POP() + di + 2 * point2 + 1
    point2 += 1
    kind.add(ti)
    Score = max(Score, Test)

print(Score)

Buggy submission (verdict: Runtime Error):
#ABC116D-VariousSushi.py

from sys import stdin
from numpy import sum

input = stdin.readline

N, K = [int(n) for n in input().split()]
INPUT = [[None for i in range(2)] for j in range(N)]
List1, List2 = [], []
kind1 = []
flag1 = 0

for i in range(N):
    INPUT[i][0], INPUT[i][1] = [int(m) for m in input().split()]

INPUT = sorted(INPUT, key = lambda x: x[1], reverse=True)

for i in range(N):
    if INPUT[i][0] not in kind1:
            List1.append([INPUT[i][1], 1])
            kind1.append(INPUT[i][0])
    else: List1.append([INPUT[i][1], 0])

List2 = List1[K:]
if List2 != []:
    List2.sort(key =lambda x : (x[1],x[0]))
    del List1[K:]
    lenList2 = len(List2)
else: lenList2 = 0

List1 = sorted(List1, key = lambda x : (x[1], x[0]), reverse=True)

sum = sum(List1, axis = 0)

Score = sum[0] + sum[1]**2
Test = Score
kindnumber = sum[1]

for i in range(lenList2):
    if List2[-1][1] == 0 or List1[-1] == 1:
        break
    Test = Test - List1.pop()[0] + List2.pop()[0] + 2 * kindnumber + 1
    kindnumber = kindnumber + 1
    if Test >= Score:
        Score = Test
    i = i - 1

print(int(Score))

Buggy submission (verdict: Runtime Error):
#ABC116D-VariousSushi.py

from sys import stdin
from numpy import sum

input = stdin.readline

N, K = [int(n) for n in input().split()]
INPUT = [[None for i in range(2)] for j in range(N)]
List1, List2 = [], []
kind1 = []
flag1 = 0

for i in range(N):
    INPUT[i][0], INPUT[i][1] = [int(m) for m in input().split()]

INPUT = sorted(INPUT, key = lambda x: x[1], reverse=True)

for i in range(N):
    if INPUT[i][0] not in kind1:
            List1.append([INPUT[i][1], 1])
            kind1.append(INPUT[i][0])
    else: List1.append([INPUT[i][1], 0])

List2 = List1[K:]
List2.sort(key =lambda x : (x[1],x[0]))
del List1[K:]
List1 = sorted(List1, key = lambda x : (x[1], x[0]), reverse=True)

sum = sum(List1, axis = 0)

Score = sum[0] + sum[1]**2
Test = Score
lenList2 = len(List2)
kindnumber = sum[1]

for i in range(lenList2):
    if List2[-1][1] == 0 or List1[-1] == 1:
        break
    Test = Test - List1.pop()[0] + List2.pop()[0] + 2 * kindnumber + 1
    kindnumber = kindnumber + 1
    if Test >= Score:
        Score = Test
    i = i - 1

print(int(Score))

Buggy submission (verdict: Runtime Error):
#ABC116D-VariousSushi.py

import sys
import numpy as np

input = sys.stdin.readline

N, K = [int(n) for n in input().split()]
INPUT = [[None for i in range(2)] for j in range(N)]
List1, List2 = [], []
kind1, kind2 = [], []

for i in range(N):
    INPUT[i][0], INPUT[i][1] = [int(m) for m in input().split()]

INPUT = sorted(INPUT, key = lambda x: x[1], reverse=True)

for i in range(N):
    if INPUT[i][0] not in kind1:
        if len(List1) < K:
            List1.append(INPUT[i][1])
            kind1.append(INPUT[i][0])
    elif INPUT[i][0] not in kind2:
        List2.append(INPUT[i][1])
        kind2.append(INPUT[i][0])

List2.sort()

kindnumber = len(kind1)
k = len(List2)-(K-kindnumber)

Score = np.sum(List1) + np.sum(List2[k:]) + kindnumber ** 2
del List2[k:]
Test = Score

for i in range(kindnumber):
    Test = Test - List1.pop() + List2.pop() - 2 * kindnumber + 1
    kindnumber = kindnumber - 1
    if Test >= Score:
        Score = Test
    if List2 == []:
        break

print(int(Score))

Buggy submission (verdict: Runtime Error):
#ABC116D-VariousSushi.py

import sys
import numpy as np
from operator import itemgetter

input = sys.stdin.readline

INPUT1 = [int(n) for n in input().split()]

N, K = INPUT1[0], INPUT1[1]
List1, List2 = [], []
Score= 0
kind = []

for i in range(N):
    INPUT2 = [int(m) for m in input().split()]
    if INPUT2[0] not in kind and len(List1) <= K:
        List1.append(INPUT2[1])
        kind.append(INPUT2[0])
    elif INPUT2[0] in kind:
        List2.append(INPUT2[1])

List1.sort(reverse=True)
List2.sort()

kindnumber = len(List1)
k = len(List2)-(K-kindnumber)

Score = np.sum(List1) + np.sum(List2[k:]) + kindnumber ** 2
del List2[k:]
Test = Score

for i in range(kindnumber):
    Test = Test - List1.pop() + List2.pop() - 2 * kindnumber + 1
    kindnumber = kindnumber - 1
    if Test >= Score:
        Score = Test
    if List2 == []:
        break

print(int(Score))