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):
#!/usr/bin/env python3
 
k, n = map(int, input().split())
A = list(map(int, input().split()))
A += [A[0] + K]
max_gap = max(y - x for x, y in zip(A, A[1:]))
print(K - max_gap)

#!/usr/bin/env python3
 
K, N = map(int, input().split())
A = list(map(int, input().split()))
A += [A[0] + K]
max_gap = max(y - x for x, y in zip(A, A[1:]))
print(K - max_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):
k,n=map(int,input().split())
a=list(map(int,input().split()))

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

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])
  
s=k-l

print(s)

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()))
l=l+[l[0]]
l=l[::-1]
ans=k
for i in range(n):
  ans=min(l[i+1]-l[i],k-(l[i+1]-l[i]))
print(ans)

k,n=map(int,input().split())
import numpy as np
l=list(map(int,input().split()))
l=np.array(l+[l[0]+k])
print(k-np.max(np.diff(l)))

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):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)-1):
    d.append([i,a[i+1]-a[i]])
d[-1][1]+=a[0]
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
if o==len(a)-1:
    g=a[-2]-a[0]
else:
    g=a[o]+n-a[o+1]
print(g)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)):
    d.append([i,a[i+1]-a[i]])
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
g=a[o]+n-a[o+1]
print(g)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)-1):
    d.append([i,a[i+1]-a[i]])
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
g=a[o]+n-a[o+1]
print(g)

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)-1):
    d.append([i,a[i+1]-a[i]])
l=sorted(d,key=lambda x:x[1])
print(l)

o=d[-1][0]
g=a[o]+n-a[o+1]


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.append(n)
d=[]
for i in range(len(a)-1):
    d.append([i,a[i+1]-a[i]])
d[-1][1]+=a[0]
l=sorted(d,key=lambda x:x[1])

o=l[-1][0]
if o==len(a)-2:
    g=a[-2]-a[0]
else:
    g=a[o]+n-a[o+1]
print(g)

Verdicts: Wrong Answer

Runtime Error

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):
# Traveling Salesman around Lake https://atcoder.jp/contests/abc160/tasks/abc160_c
N,K= map(int, input().split())

Travel_List=list(map(int,input().split()))
for i in range(K):
    Travel_List.append(Travel_List[i]+N)

Answer =0 
for i in range(K):
    print(i)
    Temp = Travel_List[i+K-1]-Travel_List[i]
    if (i==0) or (Temp<Answer):
        Answer=Temp
    


    
print(Answer)

# Traveling Salesman around Lake https://atcoder.jp/contests/abc160/tasks/abc160_c
N,K= map(int, input().split())

Travel_List=list(map(int,input().split()))
for i in range(K):
    Travel_List.append(Travel_List[i]+N)

Answer =0 
for i in range(K):
    Temp = Travel_List[i+K-1]-Travel_List[i]
    if (i==0) or (Temp<Answer):
        Answer=Temp
    


    
print(Answer)

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()))

A.insert(0, 0)
A.append(K)

print(A)

start = A[1] - A[0]
goal = A[-1] - A[-2]

mixi = 0
sum_len = 0

SorG = max(start, goal)

for i in range(len(A) - 1):
    if A[i+1] - A[i] > mixi:
        mixi = A[i+1] - A[i]
    sum_len += A[i+1] - A[i]

if max(SorG, mixi) == SorG or SorG == mixi:
    result = sum_len - (start + goal)
elif max(SorG, mixi) == mixi:
    result = sum_len - mixi

print(result)
    


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

A.insert(0, 0)
A.append(K)

# print(A)

start = A[1] - A[0]
goal = A[-1] - A[-2]

mixi = 0
sum_len = 0

# SorG = max(start, goal)

SorG = start + goal

for i in range(len(A) - 1):
    if A[i+1] - A[i] > mixi:
        mixi = A[i+1] - A[i]
    sum_len += A[i+1] - A[i]

if max(SorG, mixi) == SorG or SorG == mixi:
    result = sum_len - (start + goal)
elif max(SorG, mixi) == mixi:
    result = sum_len - mixi

print(result)
    


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()))

m = K - A[N-1] + A[0]

for i in range(N-1):
  m = min(m, A[i+1] - A[i])

print(K - m)


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

m = K - A[N-1] + A[0]

for i in range(N):
  m = min(m, A[i+1] - A[i])

print(K - m)

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

m = K - A[N-1] + A[0]

for i in range(N-1):
  m = max(m, A[i+1] - A[i])

print(K - m)


Verdicts: Wrong Answer

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 sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

k, n, *lst = map(int, read().split())
lst.sort()
dis = 0
for i in range(n):
    if i == 0:
        dis = max(dis, k-lst[-1])
    else:
        dis = max(dis, lst[i] - lst[i - 1])

dis = min(dis, k - dis)
print(dis)

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

k, n, *lst = map(int, read().split())
lst.sort()
dis = k
for i in range(n):
    if i == 0:
        tmp=lst[-1] - lst[0]
    else:
        tmp=k - lst[i] + lst[i - 1]
    dis=min(dis, tmp)
print(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):
ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = 0
for i in range(len(fff) - 1):
    distance = int(fff[i+1]) - int(fff[i])
    if longest_distance < distance:
        longest_distance = distance
shortest_road = int(eee[0]) - longest_distance
print(shortest_road)

ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = int(eee[0]) - int(fff[-1])
for i in range(len(fff) - 1):
    distance = int(fff[i+1]) - int(fff[i])
    if longest_distance < distance:
        longest_distance = distance
shortest_road = int(eee[0]) - longest_distance
print(shortest_road)

ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = 0

for i in range(len(fff - 1)):
    distance = fff[i+1] - fff[i]
    if longest_distance < distance:
        longest_distance = distance

shortest_road = eee[0] - longest_distance

print(shortest_road)


ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = int(eee[0]) + int(fff[0]) - int(fff[-1])
for i in range(len(fff) - 1):
    distance = int(fff[i+1]) - int(fff[i])
    if longest_distance < distance:
        longest_distance = distance
shortest_road = int(eee[0]) - longest_distance
print(shortest_road)


Verdicts: Wrong Answer

Wrong Answer

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()))
li = []
for i in range(N - 1):
  li.append(A[i + 1] - A[i]) 

li.append(abs(A[0] + (K - A[-1]))) 
print(sum(li) - max(li))

K, N = map(int,input().split())
A = list(map(int, input().split()))
li = []
for i in range(N - 1):
  li.append(A[i + 1] - A[i]) 
li.append(abs(A[0] + (K - A[-1]))) 
print(sum(li) - max(li))

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):
def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=0
    X = A[len(A)-1] - A[0]
    X_min = X
    A=around(K,A)
    
print(X_min)

def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=
    X = A[len(A)-1] - A[0]
    if X_min > X:
        X_min = X
    A=around(K,A)
    
print(X_min)

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

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )

Verdicts: Wrong Answer

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 = int(input())
N = int(input())

A = []

for i in range(N):
    A.append(int(input()))
    
max = A[0]
memo = 0

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

if max < K-A[N-1]+A[0]:
    max = K-A[N-1]+A[0]
    
print(K-max)
    


K = int(input())
N = int(input())

A = list(range(N))

for i in range(N):
    A[i]=int(input())
    
max = 0

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

if max < K-A[N-1]+A[0]:
    max = K-A[N-1]+A[0]
    
print(K-max)

K = int(input())
N = int(input())

A = [0]

for i in range(N):
    A[i]=int(input())

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

if max < K-A[N-1]+A[0]:
    max = K-A[N-1]+A[0]
    
print(K-max)
    


K = int(input())
N = int(input())

A = list(range(N))

for i in range(N):
    A[i]=int(input())
    
max = A[0]

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

if max < K-A[N-1]+A[0]:
    max = K-A[N-1]+A[0]
    
print(K-max)
    


K = int(input())
N = int(input())

A = list(range(N))

for i in range(N):
    A[i]=int(input())
    
max = A[0]

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

if max < K-A[N-1]+A[0]:
    max = K-A[N-1]+A[0]
    
print(K-max)
    


K,N = map(int,input().split())
A = list(map(int,input().split()))
    
max = K-A[-1]+A[0]
 
for i in range(N-1):
    if max < A[i+1]-A[i]:
        max = A[i+1]-A[i]
    
print(K-max)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

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())
l= list(map(int,input().split()))
li = []

for i in range(n):
  li.append(l[n-1]-l[n-2])

li.sort(reverse=True)
print(k-li[0])

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

for i in range(n-1):
  li.append(l[n-i-1]-l[n-i-2])

li.sort(reverse=True)
print(k-li[0])


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

for i in range(n):
  if i != n-1:
    li.append(l[n-i-1]-l[n-i-2])
  else:
    li.append(k-l[n-1]-l[0])

li.sort(reverse=True)
print(k-li[0])

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

for i in range(n):
  if i != n-1:
    li.append(l[n-i-1]-l[n-i-2])
  else:
    li.append(k-l[n-1]+l[0])

li.sort(reverse=True)
print(k-li[0])

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 = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N-1):
  if abs(a[i+1] - a[i]) >= max_d:
    max_d = abs(a[i+1] - a[i])

print(max_d,K-max_d)


K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N):
  if a[i] >= int(K/2):
    a[i] = a[i]-int(K/2)
  if abs(a[i+1] - a[i]) >= max_d:
    max_d = abs(a[i+1] - a[i])

print(K-max_d)
  

K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N):
    if a[i+1] - a[i] >= 0 and a[i+1] - a[i] >= max_d:
      max_d = a[i+1] - a[i]
    elif a[i+1] - a[i] < 0 and a[i+1] - a[i] +K >= max_d:
      max_d = a[i+1] - a[i] + K
      
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):
k, n = map(int, input().split())
a = list(map(int, input().split()))

lst = []
for i in range(0, len(a)-1) :
    lst += [a[i + 1] - a[i]]
lst += [k - a[-1] + a[0]]
print(lst)

print(sum(lst) - max(lst))


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

lst = []
for i in range(0, len(a)-1) :
    lst += [a[i + 1] - a[i]]
lst += [k - a[-1] + a[0]]

print(sum(lst) - max(lst))


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()))
k_diff = []

for i in range(1,n):
    k_diff.append(abs(a[i-1] - a[i]))

k_diff.append(k - a[-1])

print(k - max(k_diff))

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

a = list(map(int,input().split()))
k_diff = []

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

k_diff.append((k-a[-1])+a[0])

print(k - max(k_diff))


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=int(input().split()[0])
lst=list(map(int,input().split()))
lst.append(K-sum(lst))
print(K-min(lst))

K=int(input().split()[0])
lst1=list(map(int,input().split()))
lst2=[lst1[i+1]-lst1[i] for i in range(len(lst1)-1)]
lst2.append(K+lst1[0]-lst1[-1])
print(K-max(lst2))

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()))

end = a[0] + k - a[n-1]
b = []
b.append(end)

for i in range(0,n-1):
    diff = a[i+1] - a[i]
    b.append(diff)

b.sort(reverse=True)
print(k-max)

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

ans = a[0] + k - a[n-1]
for i in range(n-1):
    diff = a[i+1] - a[i]
    ans = max(ans, diff)

print(k - 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):
info = list(map(int,input().split()))
k=info[0]
n=info[1]
a = list(map(int,input().split()))
MAX=0

for i in range(n-1):
    if a[i+1]-a[i] > MAX:
        MAX=a[i+1]-a[i]
if abs(k-a[n-1]) > MAX:
        MAX=abs(k-a[n-1])
print(str(k-MAX))

info = list(map(int,input().split()))
k=info[0]
n=info[1]
a = list(map(int,input().split()))
MAX=0

for i in range(n-1):
    if a[i+1]-a[i] > MAX:
        MAX=a[i+1]-a[i]
if a[0]+k-a[n-1] > MAX:
        MAX=a[0]+k-a[n-1]
print(str(k-MAX))

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
 
tmp =list(map(int, input().split()))
num=list(map(int, input().split()))
 
a[a>int(tmp[0]//2)]=a[a>int(tmp[0]//2)]-int(tmp[0]//2)
print(sum(a))

import numpy as np

tmp =list(map(int, input().split()))
num=np.array(list(map(int, input().split())))

r = np.diff(num).sum()

l=np.array(num[num>int(tmp[0]//2)].tolist()+num[num<=int(tmp[0]//2)].tolist())
l[l>int(tmp[0]//2)]=tmp[0]-l[l>int(tmp[0]//2)]
l=np.abs(np.diff(l)).sum()

if l>r:
    print(r)
else:
    print(l)

import numpy as np

tmp = list(map(int, input().split()))
num = list(map(int, input().split()))

print(np.diff(num).sum()-np.diff(num).max())


import numpy as np
 
tmp =list(map(int, input().split()))
a=np.array(list(map(int, input().split())))
 
a[a>int(tmp[0]/2)]=tmp[0]-a[a>int(tmp[0]/2)]
print(sum(a))

import numpy as np
 
tmp =list(map(int, input().split()))
a=np.array(list(map(int, input().split())))

a[a>int(tmp[0]//2)]=tmp[0]-a[a>int(tmp[0]//2)]
print(sum(a))

import numpy as np
 
tmp =list(map(int, input().split()))
a=np.array(list(map(int, input().split())))
 
a[a>int(tmp[0]//2)]=a[a>int(tmp[0]//2)]-int(tmp[0]//2)
print(sum(a))

import numpy as np

tmp =list(map(int, input().split()))
num=list(map(int, input().split()))

a[a>int(tmp[0]//2)]=np.abs(a[a>int(tmp[0]//2)]-int(tmp[0]//2))

print(sum(a))

import numpy as np
 
tmp =list(map(int, input().split()))
num=list(map(int, input().split()))

num.append(num[0]+tmp[0])

print(np.diff(num).sum()-np.diff(num).max())


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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 = input().split()
A = [int(val) for val in A]
A_org = min(A)
A = [val - A_org for val in A]
A.sort()
dist = []
for i in range(len(A)):
  if i != len(A)-1:
    dist.append(A[i+1]-A[i])
  else:
    dist.append(K-A[i])
print(max(dist)-min(dist))

K, N = map(int, input().split())
A = input().split()
A = [int(val) for val in A]
A_org = min(A)
A = [val - A_org for val in A]
A.sort()
dist = []
for i in range(len(A)):
  if i != len(A)-1:
    dist.append(A[i+1]-A[i])
  else:
    dist.append(K-A[i])
print(K - max(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):
import numpy as np

k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(k)
b = []
for k in range(len(a)):
  b.append(a[k+1] - a[k])
print(k - argmax(b))

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

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):
#C traveling salesman around lake

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

print(a)
ans = 0
for i in range(n-1):
    if a[i+1] - a[i] > ans:
        ans = a[i+1] - a[i]

last = a[0] + k - a[n-1]
if last > ans:
    ans = last

print(k-ans)

#C traveling salesman around lake

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

ans = 0
for i in range(n-1):
    if a[i+1] - a[i] > ans:
        ans = a[i+1] - a[i]

last = a[0] + k - a[n-1]
if last > ans:
    ans = last

print(k-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):

N, X, Y = map(int, input().split())


min = []
ans = []


for i in range(0, N -1):
    d = A[i+1] - A[i]
    ans += d
    if d > max:
        max = d


dl = K - A[N - 1]
if dl < max:
    ans = ans - max + dl + A[0]


for j in range(0, N -1):
    print(ans[j])



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

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


ans = 0
max = 0


for i in range(0, N -1):
    d = A[i+1] - A[i]
    ans += d
    if d > max:
        max = d


dl = K - A[N - 1]
if dl + A[0] < max:
    ans = ans - max + dl + A[0]


print(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())
x1 = list(map(int,input().split()))
x2 = np.array(x1, dtype=np.int64)

x2 = np.sort(x2)
sum = 0

for i in range(N-1):
    sum += x2[1] - x2[0]
    
print(sum)

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

sub_x_list = x_list.copy()[1:]
sub_x_list.append(K + x_list[0])

for i in range(N):
    sub_x_list[i] -= x_list[i]
    
max_i = max(sub_x_list)
print(K - max_i)

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):
# coding: utf-8
# Your code here!

input1 = [int(x) for x in input().split()]
lake = input1[0]
homes = input1[1]
input2 = [int(x) for x in input().split()]

result = 1000000
last = homes - 1
for x in range(homes):
    forward = 0
    backward = 0
    start = input2[x]

    # forward
    if x == 0:
        forward = input2[last] - start
    else:
        forward = (lake - start) + input2[x - 1]
    
    # backward
    if x == last:
        backward = (start) - input2[0]
    else:
        backward = (start) + lake - (input2[x + 1])

    print("forward: {}, backward: {}".format(forward, backward))
    result = min(result, forward, backward)

print(result)


# coding: utf-8
# Your code here!

input1 = [int(x) for x in input().split()]
lake = input1[0]
homes = input1[1]
input2 = [int(x) for x in input().split()]

result = 1000000
last = homes - 1
for x in range(homes):
    forward = 0
    backward = 0
    start = input2[x]

    # forward
    if x == 0:
        forward = input2[last] - start
    else:
        forward = (lake - start) + input2[x - 1]
    
    # backward
    if x == last:
        backward = (start) - input2[0]
    else:
        backward = (start) + lake - (input2[x + 1])

    #print("forward: {}, backward: {}".format(forward, backward))
    result = min(result, forward, backward)

print(result)


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(x) for x in input().split())
A = list(map(int,input().split()))
check = K- A[N-1]

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

num = K - check
print(num)

K,N=(int(x) for x in input().split())
A = list(map(int,input().split()))
print(K)
print(N)
print(A)
check = K- A[N-1]

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

num = K - check
print(num)

K,N=(int(x) for x in input().split())
A = list(map(int,input().split()))
check = K- A[N-1] + A[0]

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

num = K - check
print(num)

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()))

ad = []
for i in range(n):
    if i != (n-1):
        ad.append(a[i+1] - a[i])
    if i == (n-1):
        ad.append(k-a[n-1] + a[0])

ad_max = max(ad)
ad_max_ind = ad.index(ad_max)

print(ad_max_ind)

if ad_max_ind == (n-1):
    ans = a[n-1] - a[0]
if ad_max_ind != (n-1):
    ans = k - a[ad_max_ind+1] + a[ad_max_ind]
    
print(ans)

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

ad = []
for i in range(n):
    if i != (n-1):
        ad.append(a[i+1] - a[i])
    if i == (n-1):
        ad.append(k-a[n-1] + a[0])

ad_max = max(ad)
ad_max_ind = ad.index(ad_max)

if ad_max_ind == (n-1):
    ans = a[n-1] - a[0]
if ad_max_ind != (n-1):
    ans = k - a[ad_max_ind+1] + a[ad_max_ind]
    
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(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])
print(K - max(y-x for x,y in zip(A,A[1:])))

K,N = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])
A += [A[0]+K]
print(K - max(y-x for x,y in zip(A,A[1:])))

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(i) for i in input().split()]
a = [int(i) for i in input().split()]
dmax = 0
for i in range(1,n):
  if a[i]-a[i-1]>dmax:
    dmax = a[i]-a[i-1]
print(k-dmax)

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

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()))
dist = [k-dist[n-1]+dist[0]]
for i in range(n):
  dist.append(a[i+1]-a[i])

print(k-max(dist))


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

print(k-max(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 = [int(x) for x in input().split()]
a_ = [x - a[0] for x in a] + [k]
d = [y - x for x, y in zip(a, a[1:])]
print(k - max(d))

k, n = map(int, input().split())
a = [int(x) for x in input().split()]
a_ = [x - a[0] for x in a] + [k]
d = [y - x for x, y in zip(a_, 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):
a,b = map(int,input().split())
c = [int(i) for i in input().split()]

result = sum(c) - c[0]



print(result)

a,b = map(int,input().split())
aaa = [int(i) for i in input().split()]

aaa.append(aaa[0] + a)

result = [c1 - c0 for c0,c1 in zip(aaa,aaa[0:])]

print(a - max(result))

a,b = map(int,input().split())
aaa = [int(i) for i in input().split()]

aaa.append(aaa[0] + a)

result = [c1 - c0 for c0,c1 in zip(aaa,aaa[1:])]

print(a - max(result))

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())))

ans = []
for i in range(N-1):
    ans.append(A[i+1]-A[i])

ans.append(K-A[N-1])
print(K-max(ans))

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

ans = []
for i in range(N-1):
    ans.append(A[i+1]-A[i])

ans.append(K-A[N-1]+A[0])
print(K-(max(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):
#C

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

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

d = []

d.append(a[0])
for i in range(n-1):
    d.append(a[i+1] - a[i])

d.append(k - a[n-1])
# print(d)

# print(max(d))

# print(sum(d))

print(k - max(d))

#C

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

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

d = []
d.append(a[0])
for i in range(n-1):
    d.append(a[i+1] - a[i])

d.append(k - a[n-1])

print(sum(d) - max(d))

#C

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

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

d = []

for i in range(n-1):
    d.append(a[i+1] - a[i])

d.append(k - a[n-1] + a[0])

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):
K, N = map(int, input().split())
A = list(map(int, input().split()))

ans = sum(A)

ans -= max((A[(i + 1) % N] - A[i]) % K for i in range(N))

print(ans)


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

ans = K - max((A[(i + 1) % N] - A[i]) % K for i in range(N))

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())
li = list(map(int, input().split()))
li_2 = []
for i in range(1,len(li)):
  li_2.append(li[i]-li[i-1])
print(k-max(li_2))



k, n = map(int, input().split())
li = list(map(int, input().split()))
print(k-max(li))

k, n = map(int, input().split())
li = list(map(int, input().split()))
li_2 = []
for i in range(1,len(li)):
  li_2.append(li[i]-li[i-1])
print(min(k-max(li_2), li[-1]-li[0]))



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=list(map(int, input().split(' ')))
a=list(map(int, input().split(' ')))
m=a[0]
for i in range(k[1]):
    if i==k[1]-1:
        if k[0]-a[i]+a[0]>m:
            m=k[1]-a[i]+a[0]>m
    else:
        if a[i+1]-a[i]>m:
            m=a[i+1]-a[i]>m
print(k[0]-m)

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

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 sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    k,n = IL()
    a = list(IL())
    a.sort()
    dist = []
    for i in range(n):
        if i<n-1:
            dist.append(a[i+1]-a[i])
        else:
            dist.append(k-a[i]+a[0])
    print(dist)
    x = max(dist)
    print(k-x)
    return

if __name__=='__main__':
    Main()

import sys
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    k,n = IL()
    a = list(IL())
    a.sort()
    m = 0
    for i in range(n):
        if i<n-1:
            m = max(m,a[i+1]-a[i])
        else:
            m = max(m,k-a[i]+a[0])
    print(k-m)
    return

if __name__=='__main__':
    Main()

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()))


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    for i in range(1,N):
          l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    for i in range(1,N):
          l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1]+A[0])
    print(l_s)
    m1 = max(l_s)
    ans = K-m1
    print(ans)

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


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    for i in range(1,N):
          l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1]+A[0])
    print(l_s)
    m1 = max(l_s)
    ans = K-m1
    print(ans)

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


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    m1 = max(l_s)
    ans = K-1 -m1
    print(ans)

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


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    m1 = max(l_s)
    ans = K-m1
    print(ans)

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


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    for i in range(1,N):
          l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    for i in range(1,N):
        l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1]+A[0])
    m1 = max(l_s)
    ans = K-m1
    print(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):
K, N = map(int, input().split())
A = [int(e) for e in input().split()]

ans = 0
for i in range(N - 1):
    S = [A[i] - A[i + 1]]
    S.append(A[N] - A[0])
    S.sort
    for n in range(N - 1):
        ans += S[i]
print(ans)

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

ans = 0
for i in range(N - 1):
    S = [A[i + 1] - A[i]]
    S.append((K - A[N - 1]) + A[0])
    m = sorted(S)
    for n in range(N - 1):
        ans += m[n]
print(ans)


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

ans = 0
S = [(A[i + 1] - A[i]) for i in range(N - 1)]
S.append((K - A[N - 1]) + A[0])
S.sort
m = sorted(S)
for n in range(N - 1):
    ans += m[n]
print(ans)


Verdicts: Runtime Error

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=[int(s) for s in input().split(" ")]

Smax=0
for i in range(K):
    S=0
    if i==0:
        S=max(abs(A[0]-A[-1]),abs(A[0]-A[1]))
    elif i==K-1:
        S=max(abs(A[-1]-A[0]),abs(A[-1]-A[-2]))
    else:
        S=max(abs(A[i]-A[i+1]),abs(A[i]-A[i-1]))
    if Smax<S:
        Smax=S

print(K-Smax)

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

Smax=0
for i in range(len(A)-1):
    S=0
    if i!=K-1:
        S=abs(A[i]-A[i+1])
    else:
        S=abs(A[-1]-A[0])
    if S>Smax:
        Smax=S

print(K-Smax)

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

Smax=0
for i in range(N):
    S=0
    if i!=N-1:
        if A[i+1]>A[i]:
            S=A[i+1]-A[i]
        else:
            S=A[i]-A[i+1]
    else: 
        if A[0]>A[-1]:
            S=A[0]-A[-1]
        else:
            S=A[-1]-A[0]
    
    if S>K/2:
        S=K-S
    if Smax<S:
        Smax=S

print(K-Smax)

Verdicts: Runtime Error

Wrong Answer

Accepted