TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
A = list(map(int,input().split()))

foK,N = map(int,input().split())
A = list(map(int,input().split()))
ans = []

for i in range(N-1):
  now = i
  pre = now-1
  post = now +1
  
  if now == 0:
    preDic = (K-A[N-1])+A[now]
  else:
    preDic = A[now]-A[pre]
  postDic = A[post]-A[now]  
  if preDic >= postDic:
    ans.append(K-preDic)
  else:
    ans.append(K-postDic)

    
print(min(ans))

K,N = map(int,input().split())
A = list(map(int,input().split()))
ans = []

for i in range(N-1):
  now = i
  pre = now-1
  post = now +1
  
  if now == 0:
    preDic = (K-A[N-1])+A[now]
  else:
    preDic = A[now]-A[pre]
  postDic = A[post]-A[now]  
  if preDic >= postDic:
    ans.append(K-preDic)
  else:
    ans.append(K-postDic)
  
print(min(ans))

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int, input().split()))

dist = [0] * (N-1)

for i in range(N-1):
  dist[i] = A[i+1] - A[i]
    
print(K - max(dist))

K, N = map(int, input().split())
A = list(map(int, input().split()))

inv_ans = 0

for i in range(N-1):
  if inv_ans < A[i+1] - A[i]:
    inv_ans = A[i+1] - A[i]

print(K - inv_ans)

K, N = map(int, input().split())
A = list(map(int, input().split()))

dist = [0] * (N)

for i in range(N-1):
  dist[i] = A[i+1] - A[i]
dist[N-1] = A[0] - A[-1] + K

print(K - max(dist))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = list(map(int,input().split()))
a = list(map(int,input().split()))
max_d = 0
for idx, i in enumerate(a):
    if idx == n - 1:
        if max_d < n - a[-1] + a[0]:
            max_d = n - a[-1] + a[0]
    else:
        if max_d < a[idx + 1] - i:
            max_d = a[idx + 1] - i
print(k - max_d)

k, n = list(map(int,input().split()))
a = list(map(int,input().split()))
max_d = 0
a.append(a[0] + k)
print(a)
for idx, i in enumerate(a[:-1]):
    if max_d < a[idx + 1] - i:
        max_d = a[idx + 1] - i
    
print(k - max_d)

k, n = list(map(int,input().split()))
a = list(map(int,input().split()))
max_d = 0
a.append(a[0] + k)
for idx, i in enumerate(a[:-1]):
    if max_d < a[idx + 1] - i:
        max_d = a[idx + 1] - i
print(k - max_d)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np

K, N = map(int, input().split())
A = [int(x) for x in input().split()]
A.append(K)

diff_A = []
for i in range(N):
    diff_A.append(A[i+1] - A[i])
diff_max = max(diff_A)
print(K - diff_max)

import numpy as np

K, N = map(int, input().split())
A = [int(x) for x in input().split()]

diff_A = []
for i in range(N-1):
    diff_A.append(A[i+1] - A[i])
diff_max = max(diff_A)
print(K - diff_max)

import numpy as np

K, N = map(int, input().split())
A = [int(x) for x in input().split()]
A.append(K+A[0])

diff_A = []
for i in range(N):
    diff_A.append(A[i+1] - A[i])
diff_max = max(diff_A)
print(K - diff_max)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a=[0]*n
a=list(map(int, input().split()))
for i in range(n):
    if a[i]>(k+0.5)//2:
        a[i]=int((k+0.5)//2)-a[i]
la=sorted(a)
print(max(a)-la[0])

k, n = map(int, input().split())
a=[0]*n
a=list(map(int, input().split()))
for i in range(n):
    if a[i]>k/2:
        a[i]=k/2-a[i]
la=sorted(a)
print(int(max(a)-la[0]))

k,n=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*2
b[0]=max(a)-min(a)
a.sort()
b[1]=a[-1]-a[-2]
print(min(b))

k, n = map(int, input().split())
a=[0]*n
a=list(map(int, input().split()))
if (n==3)or(n==2):
    for i in range(n):
        if a[i]>(k+0.5)//2:
            a[i]=int((k+0.5)//2)-a[i]
la=sorted(a)
print(max(a)-la[0])

a,b=map(int,input().split())
list1=list(map(int,input().split()))
list1.sort()
list2=[]
for i in range(b-1):
    list2.append(list1[i+1]-list1[i])
list2.append(list1[0]+a-list1[-1])
list2.sort()
ans=[list1[-1]-list1[0],a-max(list2)]
print(min(ans))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
 
K, N, *A = map(int, read().split())
A.append([A[0] + K])
gap = max(y - x for x, y in zip(A, A[1:]))
print(K - gap)

import sys
read = sys.stdin.buffer.read
 
K, N, *A = map(int, read().split())
A.append(A[0] + K)
gap = max(y - x for x, y in zip(A, A[1:]))
print(K - gap)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
ma = 0
for i in range(N-1):
  tmp = abs(A[i] -A[i+1])
  if min(tmp,K - tmp) > ma:
    ma = min(tmp,K-tmp)
print(K - ma)
    

import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
A = np.array(A)
ma = 0
for i in range(N-1):
  if A[i+1] - A[i] > ma:
    ma = A[i+1] -A[i]
if K -(A[N-1] -A[0]) > ma:
  ma = K -(A[N-1] -A[0])
print(K -ma)


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n = map(int, input().split())
l_1 = [int(x) for x in input().split()]
l_2 = []
for i in range(n-1):
    dis = l_1[i+1]-l_1[i]
    l_2.append(dis)
dis = k-l_1[n-1]+l_1[0]
l_2.append(dis)
print(l_2)
ans = k-max(l_2)
print(ans)

k,n = map(int, input().split())
l_1 = [int(x) for x in input().split()]
l_2 = []
for i in range(n-1):
    dis = l_1[i+1]-l_1[i]
    l_2.append(dis)
dis = k-l_1[n-1]+l_1[0]
l_2.append(dis)
#print(l_2)
ans = k-max(l_2)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())

An = list(map(int, input().split()))

Ank = [0] + An[:] + [k]

node = [Ank[i+1] - Ank[i]  for i in range(len(Ank) - 1)]

print(sum(node) - max(node))

k, n = map(int, input().split())

An = list(map(int, input().split()))

def cal(An):
    if len(An) == 1:
        print(An[0])
    else:
        Ank = [0] + An[:] + [k]
    
        node = [Ank[i+1] - Ank[i]  for i in range(len(Ank) - 1)]
        print(sum(node) - max(node))
        
cal(An)

k, n = map(int, input().split())
 
An = list(map(int, input().split()))
 
node = [An[i+1] - An[i]  for i in range(len(An) - 1)]
 
node = node[:] + [k - An[n-1] + An[0]]
 
print(k - max(node))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n = map(int,input().split())
A = list(map(int,input().split()))
#A = list(map(int,input().split()))

half = k/2
ans = 0
for i in range(n):
  if A[i] >= half:
    ans += A[i] - half
  else:
    ans += A[i]
print(ans)



k,n = map(int,input().split())
A = list(map(int,input().split()))
#A = list(map(int,input().split()))

C = []

for i,v in enumerate(A):
  if i <= len(A) - 2:
    C.append(A[i+1] - A[i])
  else: 
    C.append(k - A[i] + A[0])

maxwidth = max(C)
print(k-maxwidth) 



Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
from sys import stdin, stdout  

n = stdin.readline() 
arr = [int(x) for x in stdin.readline().split()] 
K=arr[0]
N=arr[1]
n = stdin.readline() 
A = [int(x) for x in stdin.readline().split()] 
dist=[]
for i in range(0,N-1):
    dist.append(A[i+1]-A[i])
dist.append(abs(A[0]-A[-1]+K))

m=max(dist)
for idx,val in enumerate(dist):
    if(val==m):
        dist[idx]=0
        break
print(sum(dist))

from sys import stdin, stdout  

K, N = [int(c) for c in input().split()]
A = [int(c) for c in input().split()]
dist=[]
for i in range(0,N-1):
    dist.append(A[i+1]-A[i])
dist.append(abs(A[0]-A[-1]+K))

m=max(dist)
for idx,val in enumerate(dist):
    if(val==m):
        dist[idx]=0
        break
print(sum(dist))

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
A = list(map(int,input().split()

X = A[1] - A[0]
i = 1
while i < N-1:
    Y = A[i+1] - A[i]
    if X < Y:
        X = Y
    i += 1
Z = A[0] + K - A[N-1]
if X < Z:
    X = Z

print(K - X)

K,N = map(int,input().split())
A = list(map(int,input().split()))

X = A[1] - A[0]
i = 1
while i < N-1:
    Y = A[i+1] - A[i]
    if X < Y:
        X = Y
    i += 1
Z = A[0] + K - A[N-1]
if X < Z:
    X = Z

print(K - X)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int, input().split()))

A2 = [K+a for a in A]

A = A + A2
print(A)
dist1 = A[N-1] - A[0]
dist2 = A[2*N-2] - A[N-1]

print(min(dist1, dist2))


K, N = map(int, input().split())
A = list(map(int, input().split()))

A3 = A + [K+a for a in A]
dist = [A3[i+N-1] - A[i] for i in range(N)]

print(min(dist))



Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
kn = input().split()
a = input().split()

al = [int(i) for i in a]
k = int(kn[0])
n = kn[1]

ml = 20 - abs(al[len(al)-1] - al[0])
print(ml)

for i in range(len(al)):
	if i == 0:
		ml = max(ml, abs(al[0]-al[1]))
		# print(abs(al[0])-al[len(al)-1])
	elif i == len(al)-1:
		1 == 1
		
	else:

		ml = max(ml,(al[i-1]-al[i]),abs(al[i]-(al[i+1])))

		print(abs(al[len(al)-1]-(al[i+1])))


print(k-ml)



kn = input().split()
a = input().split()

al = [int(i) for i in a]
k = int(kn[0])
n = kn[1]

ml = k - abs(al[len(al)-1] - al[0])


for i in range(len(al)-1):
	ml = max(ml,abs(al[i]-(al[i+1])))


print(k-ml)



Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(int,input().split())
a=[]
a=list(map(int,input().split()))
dis=[]
dis.append(a[0]+(k-a[n-1]))
for i in range(n-1):
    dis.append(a[i+1]-a[i])
print(min(dis))

k,n=map(int,input().split())
a=[]
a=list(map(int,input().split()))
dis=[]
dis.append(a[0]+(k-a[n-1]))
for i in range(n-1):
    dis.append(a[i+1]-a[i])
print(k-max(dis))


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
from itertools import accumulate
import sys
input=lambda :sys.stdin.readline().rstrip()

k, n = map(int, input().split())
A = list(map(int, input().split()))

S = [0] + list(accumulate(A))
d = [S[i] - S[i - k] for i in range(k, n + 1)]
print(d)

k, n = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+k)

l = 0
for i in range(n):
    l = max(l, A[i+1]-A[i])
ans = k - l
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

min_dis = K+1

for i in range(len(A) -1):
  dis = A[i+1] - A[i]
  if dis < min_dis:
    ans = (i+1)+1
    min_dis = dis
print(ans)

K, N = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

max_dis = 0
total_dis = 0
for i in range(len(A)):
  if i == len(A)-1:
  	dis = A[0] + (K - A[i])
  else:
  	dis = A[i+1] - A[i]
  total_dis +=dis
  if dis > max_dis:
    max_dis = dis
print(total_dis - max_dis)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]-A[-1]+n
for i in range(n-1):
  a=A[i+1]-A[i]
  if a>ans:
    ans=a
print(k-a)

k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]-A[-1]+n
for i in range(n-1):
  a=A[i+1]-A[i]
  if a>ans:
    ans=a
print(k-ans)

k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]-A[-1]+k
for i in range(n-1):
  a=A[i+1]-A[i]
  if a>ans:
    ans=a
print(k-ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
a.sort()
amin = a[n-1] - a[0]
for i in range(n):
  if a[i] < k//2:
    b[i] = a[i] + k
  else:
    b[i] = a[i]
b.sort()
bmin = b[n-1] - b[0]
print(a,b)
print(min(amin,bmin))

k,n = map(int,input().split())
a = list(map(int,input().split()))
 
sum = a[0] - a[-1] + k
for i in range(1, n):
    sum = max(sum,a[i] - a[i - 1])
 
print(k - sum)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np
K, N = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

# min_=10**6
dA=np.diff(A)
np.append(dA,A[0]+K-A[-1])
skip_dist=np.max(dA)
ans=K-skip_dist

print(ans)

import numpy as np
K, N = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

min_=10**6
dA=np.diff(A)
np.append(dA,abs(A[0]-A[-1]))
skip_dist=max(dA)
ans=K-skip_dist

print(ans)

import numpy as np
K, N = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

# min_=10**6
dA=np.diff(A)
np.append(dA,A[0]+K-A[-1])
skip_dist=max(dA)
ans=K-skip_dist

print(ans)

import numpy as np
K, N = map(int, input().strip().split())
A = list(map(int, input().strip().split()))

# min_=10**6
dA=np.diff(A)
dA=np.append(dA,A[0]+K-A[-1])
skip_dist=max(dA)
ans=K-skip_dist

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(k - sum(a))
print(k - max(a))

k, n = map(int, input().split())
a = list(map(int, input().split()))
d = [a[i+1] - a[i] for i in range(n-1)]
d.append(k + a[0] - a[-1])
print(k - max(d))


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
X = int(input())

a = int(X / 500)*1000 + int((X%500)/5)*5
print(a)


K, N = map(int, input().split())
A = list(map(int, input().split()))

max = A[0] + (K - A[-1])
for i in range(len(A)-1):
  d = A[i+1] - A[i]
  if d > max:
    max = d
print(K-max)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
A = list(map(int,input().split()))

diff = []


for i in range(N-1):
    Diff = A[i+1] -A[i]
    diff.append(Diff)
    
diff.append(K-A[N-1]-A[0])


DIFF = sorted(diff)
print(DIFF)
if A[0] == 0:
    del DIFF[-1]

print(sum(DIFF))

K,N = map(int,input().split())
A = list(map(int,input().split()))

diff = []


for i in range(N-1):
    Diff = A[i+1] -A[i]
    diff.append(Diff)
    
diff.append(K-A[N-1]+A[0])


DIFF = sorted(diff)
print(DIFF)

del DIFF[-1]

print(sum(DIFF))

K,N = map(int,input().split())
A = list(map(int,input().split()))

diff = []


for i in range(N-1):
    Diff = A[i+1] -A[i]
    diff.append(Diff)
    
diff.append(K-A[N-1]+A[0])


DIFF = sorted(diff)

del DIFF[-1]

print(sum(DIFF))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = list(map(int, input().split()))
A = [0] * N
A = list(map(int, input().split()))

sorted_A = sorted(A)
sorted_A = [i - sorted_A[0] for i in sorted_A]

print(sorted_A)

dis = []
for i in range(len(sorted_A)-1):
    dis.append(abs(sorted_A[i] - sorted_A[i+1]))

last_dis = abs(sorted_A[-1] - sorted_A[0])

if(last_dis >= K/2):
    last_dis = K - last_dis

dis.append(last_dis)

print(K - max(dis))

K, N = list(map(int, input().split()))
A = [0] * N
A = list(map(int, input().split()))

sorted_A = sorted(A)
sorted_A = [i - sorted_A[0] for i in sorted_A]

dis = []
for i in range(len(sorted_A)-1):
    dis.append(abs(sorted_A[i] - sorted_A[i+1]))

last_dis = abs(sorted_A[-1] - sorted_A[0])

if(last_dis >= K/2):
    last_dis = K - last_dis

dis.append(last_dis)

print(K - max(dis))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
round,house_num = map(int,input().split())

distance = list(map(int,input().split()))

min = distance[-1] - distance[0]

for i in range(house_num - 1):
  if round-(distance[i+1]-distance[i]) < min:
    min = round-(distance[i+1]-distance[i])
  print(min)

n,k = map(int,input().split())
a = list(map(int,input().split()))

lis = []
for i in range(k-1):
  lis.append(a[i+1]-a[i])
lis.append(a[0]-a[-1]+n)
print(sum(lis)-max(lis))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n =  map(int,input().split())
a = list(map(int,input().split()))

#print(a)
sa =  []
for i in range(1,n):
    sa_ = a[i]-a[i-1]
    sa.append(sa_)
#print(sa)
k_last = k
for j in range(len(sa)):
    k_last -= sa[j]
#print('k_last=',k)

ans = k_last -  max(sa)
if ans < 0:
    print(max(sa))
elif ans == 0:
    print(k)
else:
    print(ans)

k,n =  map(int,input().split())
a = list(map(int,input().split()))

sa =  []
for i in range(1,n):
    sa_ = a[i]-a[i-1]
    sa.append(sa_)

sa.append(k-max(a)+min(a))
ans = sum(sa)-max(sa)
# print(sa)
# print(k)
# print(sum(sa))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
A = list(map(int,input().split()))

max_distance = K + (A[0] + A[-1])

for i in range(1,N):
  max_distance = max(max_distance, A[i] - A[i-1])
  
print(K - max_distance)

K,N = map(int,input().split())
A = list(map(int,input().split()))

max_distance = K + (A[0] - A[-1])

for i in range(1,N):
  max_distance = max(max_distance, A[i] - A[i-1])
  
print(K - max_distance)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(int,input().split())
l=list(map(int,input().split()))

diff=[]
l.append(l[0]+k)

for i in range(n-1):
  diff.append(l[n+1]-l[n])
  
print(sum(diff)-max(diff))

k,n=map(int,input().split())
l=list(map(int,input().split()))

diff=[]
l.append(l[0]+k)
for i in range(n):
  diff.append(l[i+1]-l[i])

print(sum(diff)-max(diff))


Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())

red = sorted(list(map(int, input().split())), reverse=True)[0:x-1]
gre = sorted(list(map(int, input().split())), reverse=True)[0:y-1]
non = sorted(list(map(int, input().split())), reverse=True)

eat = red + gre + non

eat.sort(reverse=True)

print(sum(eat[0:x+y-1]))


x, y, a, b, c = map(int, input().split())

red = sorted(list(map(int, input().split())), reverse=True)
gre = sorted(list(map(int, input().split())), reverse=True)
non = sorted(list(map(int, input().split())), reverse=True)

red = red[0:x]
gre = gre[0:y]

eat = red + gre + non

eat.sort(reverse=True)

print(sum(eat[0:x+y]))


Verdicts: Wrong Answer

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
import heapq

X, Y, A, B, C = map(int ,input().split(' '))
p = list(map(int ,input().split(' ')))
q = list(map(int ,input().split(' ')))
R = set(map(int ,input().split(' ')))

eat = sorted(p, reverse=True)[:X]
heapq.heapify(eat)
[heapq.heappush(eat, i) for i in sorted(q, reverse=True)[:Y]]

first = min(eat)
for r in R:
  if r > first:
    eat.remove(min(eat))
    eat.append(r)
    first = heapq.heappop(eat)
  
print(sum(eat))

X, Y, A, B, C = map(int ,input().split(' '))
p = list(map(int ,input().split(' ')))
q = list(map(int ,input().split(' ')))
R = list(map(int ,input().split(' ')))
 
eat = sorted(p, reverse=True)[:X]
eat[len(eat):] = sorted(q, reverse=True)[:Y]
eat[len(eat):] = R
eat.sort(reverse=True)


print(sum(eat[:X+Y]))

Verdicts: Wrong Answer

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
RAeatList = RA[:X]
GAeatList = GA[:Y]
while RAeatList[-1] < WA[0] or GAeatList[-1] < WA[0]:
  n= 1
  while RAeatList[-1 * n] == GAeatList[-1 * n] or n == min(X,Y) :
    n -= 1
  if RAeatList[-1 * n] < GAeatList[-1 * n]:
    RAeatList.pop(len(RAeatList) -1)
    RAeatList.insert(0,WA[0])
  else:
    GAeatList.pop(len(RAeatList) -1)
    GAeatList.insert(0,WA[0])
  if len(WA) == 1:
    break
  WA.pop(0)
  if eatWA == C:
    break

for i in range(X):
  ans += RAeatList[i]
for i in range(Y):
  ans += GAeatList[i]
print(ans)

X,Y,A,B,C =map(int,input().rstrip().split(" "))
RA = list(map(int,input().rstrip().split(" ")))
GA = list(map(int,input().rstrip().split(" ")))
WA = list(map(int,input().rstrip().split(" ")))
RA.sort()
RA.reverse()
GA.sort()
GA.reverse()
WA.sort()
WA.reverse()
eatRA = X
eatGA = Y
eatWA = 0
ans = 0
while RA[eatRA - 1] < WA[eatWA] or GA[eatGA -1] < WA[eatWA]:
  n= 1
  while RA[eatRA - n] == GA[eatGA -n] and n != min(eatRA,eatGA):
    n += 1
  if RA[eatRA - n] > GA[eatGA - n]:
    eatGA -= 1
  else:
    eatRA -= 1
  eatWA += 1
  if eatWA == C or eatRA == 0 or eatGA == 0:
    break
if eatRA == 0 and eatGA != 0 and eatWA != C:
  while GA[eatGA -1] < WA[eatWA]:
    eatGA -= 1
    eatWA += 1
    if eatWA == C or eatGA == 0:
      break
elif eatRA != 0 and eatGA == 0 and eatWA != C:
  while RA[eatRA -1] < WA[eatWA]:
    eatRA -= 1
    eatWA += 1
    if eatWA == C or eatRA == 0:
      break
for i in range(eatRA):
  ans += RA[i]
for i in range(eatGA):
  ans += GA[i]
for i in range(eatWA):
  ans += WA[i]
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(c):
  if rcount<len(r)-1 and ans[i]<=r[-1-rcount]:
    ans[i]=r[-1-rcount]
    rcount+=1
print(sum(ans))
  

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in ragne(r):
  if ans[i]<=r[-1-rcount]:
    ans[i]=r[-1-rcount]
    rcount+=1
print(sum(ans))
  

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort()
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
for i in range(r):
  if ans[i]<=r[-1-rcount]:
    ans[i]=r[-1-rcount]
    rcount+=1
print(sum(ans))
  

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort()
q.sort()
r.sort(reverse=True)
pcount=0
qcount=0
rcount=0
ans=[]
for i in range(x):
  ans.append(p[-1-i])
for i in range(y):
  ans.append(q[-1-i])
ans.sort()
print(ans,r)
for i in range(c):
  if ans[i]<=r[rcount]:
    ans[i]=r[rcount]
    rcount+=1
print(sum(ans))

x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
ans=[]
for i in range(x):
  r.append(p[i])
for i in range(y):
  r.append(q[i])
r.sort(reverse=True)
print(sum(r[0:x+y]))
  



Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
[X, Y, A, B, C] = list(map(int, input().split()))

p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

eatCandi = p[0:X] + q[0:Y] + r[0:X+Y]
print(sum(eatCandi[0:X+Y]))

[X, Y, A, B, C] = list(map(int, input().split()))

p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

eatCandi = sorted(p[0:X] + q[0:Y] + r[0:X+Y], reverse=True)

print(sum(eatCandi[0:X+Y]))


Verdicts: Wrong Answer

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
def main():
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort()
    q.sort()
    for i in range(-1, -x - 1, -1):
        r.append(p[i])
    for i in range(-1, -y - 1, -1):
        r.append(q[i])
    r.sort(reverse=True)
    print(sum(r[x + y:]))


if __name__ == '__main__':
    main()



def main():
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort()
    q.sort()
    for i in range(-1, -x - 1, -1):
        r.append(p[i])
    for i in range(-1, -y - 1, -1):
        r.append(q[i])
    r.sort(reverse=True)
    print(sum(r[:x + y]))


if __name__ == '__main__':
    main()



Verdicts: Wrong Answer

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)

A = A[len(A)-x:]
B = B[len(B)-y:]
C = list(map(lambda x: x*(-1), C))

import heapq
heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)

flag = True
while flag:
  a = heapq.heappop(A)
  b = heapq.heappop(B)
  c = heapq.heappop(C)*(-1)
  if c < a and c < b:
    flag = False
  else:
    if a-c > b-c:
      heapq.heappush(A, c)
      heapq.heappush(B, b)
      if not C:
        break
    else:
      heapq.heappush(A, a)
      heapq.heappush(B, c)
      if not C:
        break
print(sum(A) + sum())

x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A = sorted(A)
B = sorted(B)

A = A[len(A)-x:]
B = B[len(B)-y:]
C = list(map(lambda x: x*(-1), C))

import heapq
heapq.heapify(A)
heapq.heapify(B)
heapq.heapify(C)

flag = True
while flag:
  a = heapq.heappop(A)
  b = heapq.heappop(B)
  c = heapq.heappop(C)*(-1)
  if c < a and c < b:
    heapq.heappush(A, a)
    heapq.heappush(B, b)
    flag = False
  else:
    if a > b:
      heapq.heappush(A, a)
      heapq.heappush(B, c)
      if not C:
        break
    else:
      heapq.heappush(A, c)
      heapq.heappush(B, b)
      if not C:
        break
print(sum(A) + sum(B))

Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
gw = [int(i) for i in input().split()] + [int(i) for i in input().split()]
red.sort()
gw.sort()
gwrui = []
rui = 0
for i in range(b+c):
    rui += gw[i]
    gwrui.append(rui)
redq = deque(red[:x])
ans = 0
oisr = 0
for i in range(1,x+1):
    oisr += redq.popleft()
    temp = oisr
    temp += gwrui[x+y-i]
    ans = max(ans,temp)
print(ans)

from collections import deque
x,y,a,b,c = map(int,input().split())
red = [int(i) for i in input().split()]
g = [int(i) for i in input().split()]
w = [int(i) for i in input().split()]
red.sort(reverse=True)
g.sort(reverse=True)
g = g[:y]
gw = g+w
gw.sort(reverse=True)
gwrui = []
rui = 0
for i in range(y+c):
    rui += gw[i]
    gwrui.append(rui)
red = red[:x]
rrui = []
rui = 0
for i in range(x):
    rui += red[i]
    rrui.append(rui)
rrui = [0] + rrui
ans = 0
oisr = 0
lgw = len(gw)

for i in range(0,x+1):
    temp = rrui[i]
    if x+y-i <= lgw:
        temp += gwrui[x+y-i-1]
        ans = max(ans,temp)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans = p[:x] + q[:y] + r
print(sum(ans.sort(reverse=True)[:x + y]))

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ans = p[:x] + q[:y] + r
print(sum(sorted(ans, reverse=True)[:x + y]))


Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) 
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) 
for i in range(C):
    hq.heappush(pq2, -r[i])
while (pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) 
print(sum(pq1))

import heapq as hq

X, Y, A, B, C = map(int,input().split())
p = list(map(int,input().split())); p.sort(); p.reverse()
q = list(map(int,input().split())); q.sort(); q.reverse()
r = list(map(int,input().split())); r.sort(); r.reverse()

pq1 = []; hq.heapify(pq1) 
for i in range(X):
    hq.heappush(pq1, p[i])
for i in range(Y):
    hq.heappush(pq1, q[i])
pq2 = []; hq.heapify(pq2) 
for i in range(C):
    hq.heappush(pq2, -r[i])
while (len(pq2) and pq1[0] < -pq2[0]):
    hq.heappush(pq1, -hq.heappop(pq2))
    hq.heappop(pq1) 
print(sum(pq1))

Verdicts: Runtime Error

Accepted
Problem: You are going to eat X red apples and Y green apples.   You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.   Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.   From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.   Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Submission attempts (in order):
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
print(ans,sum(ansp),sum(ansq))
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
    print(ans,ep,eq)
print(ans)

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
ansp=p[:x]
ansq=q[:y]
ans=sum(ansp)+sum(ansq)
ep=x-1
eq=y-1
for i in range(c):
    if ep<0 and eq<0:
        break
    if (ep>=0 and eq<0) or (ep>=0 and eq>=0 and ansp[ep]<ansq[eq]):
        if ansp[ep]<r[i]:
            ans=ans-ansp[ep]+r[i]
            ep-=1 
        else:
            break
    elif (eq>=0 and ep<0) or (ep>=0 and eq>=0 and ansq[eq]<=ansp[ep]):
        if ansq[eq]<r[i]:
            ans=ans-ansq[eq]+r[i]
            eq-=1
        else:
          break
print(ans)

Verdicts: Wrong Answer

Accepted