Problem p03141 (python)

Fixed submission:
#%%
import time

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []

start = time.time()

for i in range(N):
  A[i], B[i] = map(int,input().split())


D = np.array(A) + np.array(B)
for i in range(N):
  C[i] = [i, D[i]]


elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
start = time.time()

C = sorted(C, key=lambda x:x[1])


elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
start = time.time()


if N %2 == 0 :
  for i in range(1,N,2):
    tmp_max = C[-i][0]
    takahashi.append(A[tmp_max])
    tmp_max = C[-i-1][0]
    aoki.append(B[tmp_max])

elif N %2 != 0 :
  for i in range(1,N-1,2):
    tmp_max = C[-i][0]
    takahashi.append(A[tmp_max])
    tmp_max = C[-i-1][0]
    aoki.append(B[tmp_max])
  tmp_max = C[-N][0]
  takahashi.append(A[tmp_max])

print(sum(takahashi)-sum(aoki))

elapsed_time = time.time() - start
#print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Buggy submission (verdict: Runtime Error):
import numpy as np
 
N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []
 
for i in range(N):
  A[i], B[i] = map(int,input().split())
 
D = np.array(A) + np.array(B)

for i in range(N):
  C[i] = [i, D[i]]
  
C = sorted(C, key=lambda x:x[1])
 
while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi.append(A[tmp_max])
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)
 
  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki.append(B[tmp_max])
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)
 
print(sum(takahashi)-sum(aoki))

Buggy submission (verdict: Runtime Error):

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []


for i in range(N):
  A[i], B[i] = map(int,input().split())


D = np.array(A) + np.array(B)
for i in range(N):
  C[i] = [i, D[i]]


C = sorted(C, key=lambda x:x[1])



while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi.append(A[tmp_max])
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki.append(B[tmp_max])
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(sum(takahashi)-sum(aoki))

Buggy submission (verdict: Runtime Error):

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0



for i in range(N):
  A[i], B[i] = map(int,input().split())


D = list(np.array(A) + np.array(B))
for i in range(N):
  C[i] = [i, D[i]]




C = sorted(C, key=lambda x:x[1])



while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)

Buggy submission (verdict: Runtime Error):
#%%
import time



import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0
for i in range(N):
  A[i], B[i] = map(int,input().split())
  C[i].append(i)
  C[i].append((np.array(A)[1] + np.array(B)[1]))



C = sorted(C, key=lambda x:x[1])




while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0
for i in range(N):
  A[i], B[i] = map(int,input().split())
  C[i].append(i)
  C[i].append(A[i]+B[i])

C = sorted(C, key=lambda x:x[1])

while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)