Problem:


Score : 300 points

Problem Statement

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.

Constraints

2 \leq K \leq 10^6

2 \leq N \leq 2 \times 10^5

0 \leq A_1 < ... < A_N < K

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K N
A_1 A_2 ... A_N

Output

Print the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Sample Input 1

20 3
5 10 15

Sample Output 1

10

If you start at the 1-st house and go to the 2-nd and 3-rd houses in this order, the total distance traveled will be 10.

Sample Input 2

20 3
0 5 15

Sample Output 2

10

If you start at the 2-nd house and go to the 1-st and 3-rd houses in this order, the total distance traveled will be 10.



Sample input:
20 3
5 10 15


Sample output:
10

Submission status: Wrong Answer

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k +a[1] - a[n - 1])

print(k - max(space))

Submission status: Wrong Answer

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k - a[n - 1])

print(k + a[1] - max(space))

Submission status: Wrong Answer

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k - a[n - 1])

print(k - max(space))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k,n = map(int, input().split())
a = list(map(int, input().split()))
dis = [0]*n
for i in range(n):
    if i == n-1:
        dis[i] = k + a[0] - a[i]
    else:
        dis[i] = a[i+1] - a[0]

print(k - max(dis))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
points = list(map(int, input().split()))

s_sum = max(points) - min(points)
e_sum = abs(points[-1] - max(map(lambda x: x+K, points[:-1])))

print(min([s_sum, e_sum]))

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
a=[int(i) for i in input().split()]


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

Submission status: Wrong Answer

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

ans = 0
max_dif = 0
for i in list(range(1, n)) + [0]:
	x = abs(a[i] - a[i-1])
	max_dif = max(max_dif, x)
	ans += x

ans -= max_dif
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(K, N, As):
    longest = 0
    for i in range(len(As)):
        if i == len(As) - 1:
            longest = max(longest, As[0] + (K - As[i]))
        elif i == 0:
            longest = max(longest, As[i])
        else:
            longest = max(longest, As[i] - As[i - 1])
    print(K - longest)


if __name__ == '__main__':
    K, N = map(int, input().split())
    As = [int(a) for a in input().split()]
    solve(K, N, As)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in a:
  i+=k
print(k-max(a)+min(a))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
a = list(map(int, input().split()))
sum_s, sum_o = 0, 0

for i in range(n-1):
    sum_o += a[i+1] - a[i]

a_ex1 = [i for i in a if i <= k // 2]
a_ex2 = [i for i in a if i > k // 2]
if len(a_ex1) != 0 and len(a_ex2) != 0:
    sum_s = max(a_ex1) + k - min(a_ex2)
elif len(a_ex1) == 0:
    sum_s = max(a_ex2) - min(a_ex2)
else:
    sum_s = max(a_ex1) - min(a_ex1)

# print(a_ex1)
# print(a_ex2)

print(min(sum_o, sum_s))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
a = list(map(int, input().split()))
sum_s, sum_o = 0, 0

for i in range(n-1):
    sum_o += a[i+1] - a[i]

a_ex1 = [i for i in a if i <= k // 2]
a_ex2 = [i for i in a if i > k // 2]
# if len(a_ex1) != 0 and len(a_ex2) != 0:
sum_s = max(a_ex1) + k - max(a_ex2)
# else if len(a_ex1) == 0:
    

# print(a_ex1)
# print(a_ex2)

print(min(sum_o, sum_s))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
a = list(map(int, input().split()))
sum_s, sum_o = 0, 0

for i in range(n-1):
    sum_o += a[i+1] - a[i]

a_ex1 = [i for i in a if i <= k // 2]
a_ex2 = [i for i in a if i > k // 2]
sum_s = max(a_ex1) + k - min(a_ex2)

# print(a_ex1)
# print(a_ex2)

print(min(sum_o, sum_s))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[10]:


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


# In[11]:


dist = []
for i in range(1,len(A)):
    dist.append(A[i]-A[i-1])
dist.append(K - A[-1])
dist_s = sorted(dist)
print(sum(dist_s[:-1]))


# In[ ]:

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
# A = [i for i in map(int, input().split())]

A2 = [A[i+1] - A[i] for i in range(N-1)]
AN = A[0]+(A[0]+(K-A[N-1]))
A2.append(AN)

print(K-max(A2))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
# A = [i for i in map(int, input().split())]


AN = A[0]+(K-sum(A))
A2 = A[1:N]
A2.append(AN)

print(sum(A2)-max(A2))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
# A = [i for i in map(int, input().split())]


AN = A[0]+A[N-1]
A2 = A[1:N]
A2.append(AN)

print(sum(A2)-max(A2))

Submission status: Wrong Answer

Solution code:
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(a[0]+k-a[n-1])    
print(sum(d)-2*min(d))

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if a[0] == 0:
    a[0] = 20
ch = a[n-1] - a[0]
for i in range(n-1):
    if a[i+1] - a[i] >= ch:
        ch = a[i+1] - a[i]
print(k-ch)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))
 
max1 = 0
ind = 0
for i in range(n-1):
    tmp = clist[i+1] - clist[i]
    if tmp > max1:
        max1 = tmp
        ind = i
        
s1 = clist[n-1]-clist[0]
s2 = (k - clist[n-1]) + clist[n-2]
s3 = clist[i]+(k-clist[i+1])

print(min(s1, s2, s3))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))
 
max1 = 0
ind = 0
for i in range(n-1):
    tmp = clist[i+1] - clist[i]
    if tmp > max1:
        max1 = tmp
        ind = i
 
print(clist[ind]+(k-clist[ind+1]))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))
 
max1 = 0
ind = 0
for i in range(n-1):
    tmp = clist[i+1] - clist[i]
    if tmp > max1:
        ind = i
 
print(clist[ind]+(k-clist[ind+1]))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))

max1 = 0
ind = 0
for i in range(n-1):
    tmp = clist[i+1] - clist[i]
    if tmp > max1:
        max1 = tmp
        ind = i

print(clist[i]+(k-clist[i+1]))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))

if n % 2 != 0:
    mid = int(n/2)
else:
    mid = int(n/2) -1
    


s1 = clist[n-1]-clist[0]
s2 = (k - clist[n-1]) + clist[n-2]
s3 = clist[mid] + (k - clist[mid+1])

print(min(s1,s2,s3))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
clist = list(map(int, input().split()))

s1 = clist[n-1]-clist[0]
s2 = (k - clist[n-1]) + clist[n-2]

print(min(s1,s2))

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
houses=list(map(int,input().split()))
houses.sort()
maxx=-float('INF')
for i in range(n-1):
    if houses[i+1]-houses[i]>maxx:
        maxx=houses[i+1]-houses[i]

maxx=max([maxx,k-(houses[-1]-houses[0])])
print(maxx)

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
houses=list(map(int,input().split()))

maxx=-float('INF')
for i in range(n-1):
    if houses[i+1]-houses[i]>maxx:
        maxx=houses[i+1]-houses[i]

maxx=max([maxx,k-(houses[-1]-houses[0])])
print(maxx)

Submission status: Wrong Answer

Solution code:
import numpy as np


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

A = list(map(int, input().split()))
A.append(K)
distances = np.diff(A)

print(sum(distances) - max(distances))

Submission status: Wrong Answer

Solution code:
k,n = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in a:
    if k-i<i:
        b.append(-(k-i))
    else:
        b.append(i)
a.sort()
b.sort()
# print(b)
print(min(a[len(a)-1]-a[0],b[len(b)-1]-b[0]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.append(N+a[0]-a[-1])
max = 0
for i in range(len(a)-1):
  p = abs(a[i]-a[i+1])
  max = p if max < p else max
print(N-max)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0]) if a[0] != 0 else a.append(N)
max = 0
for i in range(len(a)-1):
  p = abs(a[i]-a[i+1])
  max = p if max < p else max
print(N-max)

Submission status: Wrong Answer

Solution code:
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


def main():

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

    if N == 2:
        d = abs(A[0]-A[1])
        print(min(d, K-d))
    else:
        max_d = N - A[N-1] + A[0]
        for i in range(N - 1):
            max_d = max(max_d, abs(A[i] - A[i+1]))
        print(K - max_d)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = -9878789894545656
 
for i in range(n):
  m = max(m,abs(a[i+1]-a[i]))
  
print(k-m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = 11414114514
 
for i in range(n):
  m = min(m,a[i+1]-a[i])
  
print(k-m)

Submission status: Wrong Answer

Solution code:
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:])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*2
b[0]=max(a)-min(a)
a.sort()
if 0 in a:
    b[1]=a[-1]-a[1]
else:
    b[1]=100000000
print(min(b))

Submission status: Wrong Answer

Solution code:
def main():
    k, n = map(int, input().split())
    As = list(map(int, input().split()))

    diffs = [0]*n
    for i in range(n):
        if i == n-1:
            diffs[i] = k - As[i]
        else:
            diffs[i] = As[i+1] - As[i]
    diffs.remove(max(diffs))
    ans = sum(diffs)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

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

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

if A[N-1] - A[0] <= K / 2:
    res = A[N-1] - A[0]
else:
    res = K - max(dist)

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 0
for i in range(1, len(A)):
    if A[i]-A[i-1]>m:
        m=A[i]-A[i-1]
if K-A[-1]+A[1]>m:
    print(A[-1]-A[1])
else:
    print(K-m)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 0
for i in range(1, len(A)):
    if A[i]-A[i-1]>m:
        m=A[i]-A[i-1]
if K-A[-1]>m:
    print(A[-1])
else:
    print(K-m)

Submission status: Wrong Answer

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

S = [0]*(N+1)

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

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

Submission status: Wrong Answer

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

S = [0]*(N+1)

for i in range(N):
    if i==N-1:
        S[i+1] = K- A[i]
    elif i == 0:
        S[i+1] = A[i]
    else:
        S[i+1] = A[i+1] - A[i]

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

Submission status: Wrong Answer

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

S = [0]*(N+1)

for i in range(N):
    if i==N-1:
        S[i+1] = K- A[i]
    else:
        S[i+1] = A[i+1] - A[i]

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

Submission status: Wrong Answer

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

S =[A[0]]+ [0]*(N)

for i in range(N):
    if i==N-1:
        S[i+1] = K- A[i]
    else:
        S[i+1] = A[i+1] - A[i]

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

Submission status: Wrong Answer

Solution code:
k,n = list(map(int, input().split()))

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

tonari_dif = 0
for i in range(1,n):
    tonari_dif = max(tonari_dif, a_vector[i] - a_vector[i-1])

true_tonari_dif = max(tonari_dif, a_vector[0]+(200-a_vector[-1]))

print(k-true_tonari_dif)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

sortA=np.sort(A)
D = sortA[1:N]-sortA[0:N-1]

print("{}".format(min([sum(D), K-min(D)])))

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
K, N = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
#print(K,N,A)
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)

Submission status: Wrong Answer

Solution code:
K,N = map(int,input().split())
A = list(map(int,input().split()))
B = [] # 逆向き
for i in range(N-1):
  tmp = A[i+1]-K
  B.append(tmp)
B.extend(A)


tmp_sum = 0
j = 0
#print(B)
dist = []
for i in range(1,len(B)):
  d = abs(B[i]-B[i-1])
  tmp_sum += d
  dist.append(d)
  if(i == N-1):
    ans = tmp_sum 
    print('ans :',ans)
  elif(i >= N):
    tmp_sum -= dist[j]
    j += 1
    ans = min(ans,tmp_sum)
    print('ans :',ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# 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)

Submission status: Wrong Answer

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

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

m = max(m, a[0] + k - a[n-1])

print(m)

Submission status: Wrong Answer

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

dist = []
for i in range(N):
  if i == N-1:
    if A[0] == 0:
      dist.append(K-A[i])
    else:
      dist.append(A[i]-A[0])
  else:
    dist.append(A[i+1]-A[i])
max_dist = max(dist)
print(sum(dist)-max_dist)

Submission status: Wrong Answer

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




a.sort()


shita = a[-1] - a[0]
ue = k + a[-2] - a[-1]

print(min(shita, ue))

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
a = list(map(int, input().split()))
aa = sorted(a,reverse=True)

if k - max(a) + aa[1] >= max(a) - min(a):
    ans = max(a) - min(a)
    print(ans)
else:
    print(k - max(a) + aa[1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    K,N = map(int,input().split())
    A_list = list(map(int,input().split()))
    dist_list = []
    A_list.append(K)
    for i in range(1,len(A_list)):
        dist_list.append(A_list[i]-A_list[i-1])
    d_sorted = sorted(dist_list)
    print(int(sum(d_sorted[0:N-1])))
main()

Submission status: Wrong Answer

Solution code:
import itertools
import math
import fractions
import functools
k, n = map(int, input().split())
a = list(map(int, input().split()))

sub = [0] * n
for i in range(n-1):
    sub[i] = a[i+1]-a[i]

sub[n-1] = k - a[n-1] + a[0]
print(sub)
print(k-max(sub))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k, n = map(int,input().split())
a = [int(x) for x in input().split()]

add = (k - a[-1]) + a[0]

diff_a = [add]
diffdiff = []
for i in range(n-1):
    d = a[i+1]-a[i]
    diff_a.append(d)
    dd = diff_a[i] + diff_a[i+1]
    diffdiff.append(dd)
    
print(min(diffdiff))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = sorted(map(int, input().split()))
m = M = A[0]
for a in A[1:]:
    ra = a - K
    if a <= M or ra >= m:
        continue
    if a - M > m - ra:
        m = ra
    else:
        M = a
print(M - m)

Submission status: Wrong Answer

Solution code:
import numpy as np
K, N = map(int, input().split())
A = np.array(input().split(), dtype=np.int32)
B = A + (A > K // 2) * (-K)
print(min(A.max() - A.min(), B.max() - B.min()))

Submission status: Wrong Answer

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

diff = [None] * N

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

diff[0] = A[0]
diff[N-1] = K - A[N-1]

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split())) 
d = []
interval = 0
for i in range(N):
  d.append(A[i] - interval)
  interval += A[i]
d.append(K-interval+A[0])
print(K - max(d))

Submission status: Wrong Answer

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

diff = [None] * N

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

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]

for i in range(N-1):
    ans.append(A[i+1]-A[i])
ans.append(abs(A[0] - (K - A[-1])))
print(sum(ans) - max(ans))

Submission status: Wrong Answer

Solution code:
# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]
for a in A:
    ans.append(min(a,K-a))
print(sum(ans))

Submission status: Wrong Answer

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

D = [0]*N

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

print(D)
print(K - D[N-1])

Submission status: Wrong Answer

Solution code:
import copy

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

B = copy.copy(A)

for i in range(N):
  if B[i] > K/2:
      B[i] -= K
      
B.sort()

print(int(min(A[N-1] - A[0], B[N-1] - B[0])))

Submission status: Wrong Answer

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

A.sort()

s = A[0]

for i in range(N):
  A[i] -= s

print(int(A[N-1] - A[0]))

Submission status: Wrong Answer

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

for i in range(N):
  if A[i] > K/2:
    A[i] = K/2 - A[i]
 
A.sort()
print(A)

print(int(A[N-1] - A[0]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

def main():
    K,N=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    mmax=0
    for a in range(1,N):
        mmax=max(mmax,abs(A[a]-A[a-1]))
    print(K-mmax)

main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################

def main():
    K,N=map(int,input().split())
    A=list(map(int,input().split()))
    mmax=0
    for a in range(1,N):
        mmax=max(mmax,abs(A[a]-A[a-1]))
    print(K-mmax)

main()

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
a = list(map(int, input().split()))
b = 0
c = 0
for i in range(-1, n-1):
	b = abs(a[i+1]-a[i])
	if b > k/2:
		b = abs(k - a[i])
	if b > c:
		c = b

print(k-c)

Submission status: Wrong Answer

Solution code:
import numpy as np
K, N = map(int, input().split())
x = list(map(int, input().split()))

x1 = x[N-1] - x[0]
x2 = K -(x[N-1]- x[N-2])

if x1 >= x2:
    print(x2)
    
else:
    print(x1)

Submission status: Wrong Answer

Solution code:
import numpy as np
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[i+1] - x2[i]
    
print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
a=[int(i) for i in input().split()]

print(min(a[-1]-a[0],a[0]+k-a[1],a[-2]-(a[-1]-k)))

Submission status: Wrong Answer

Solution code:
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.append(k+a[0])
print(k-max(a))

Submission status: Wrong Answer

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

l = [0]*n
l[-1] = k-a[-1]
for i in range(n-1):
  l[i] = a[i+1] - a[i]
print(sum(sorted(l)[:-1]))

Submission status: Wrong Answer

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

l = [0]*n
for i in range(n-1):
  l[i] = a[i+1]-a[i]
l[-1] = k-a[-1]
print(sum(sorted(l)[:n-1]))

Submission status: Wrong Answer

Solution code:
k, n = map(int, input().split())
a = sorted(list(map(int, input().split())))

if a[0] == 0:
    a[0] = k
    a.sort()

print(min(a[-1]-a[0], a[0] + k-a[-1]))