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=list(map(int,input().split()))
sales=list(map(int,input().split()))
sales2=[]
for s in sales:
  sales2.append(s+k) if s < k//2 else sales2.append(s)

sales2.sort()
print(min(sales[n-1]-sales[0],sales2[n-1]-sales2[0]))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
KN = input().split()
K = int(KN[0])
N = int(KN[1])
#print(K,N)

A = input().split()
A_np = np.append(np.array(A, dtype=np.int64), K)
A_np_lag = np.append(A_np[1:], A_np[0])
A_diff = A_np_lag[:N] - A_np[:N]
dist_np = np.append(A_diff, A_diff)
total_dist = []
for i in range(N):
    #print(dist_np[i:(i+N-1)])
    temp_total_dist = dist_np[i:(i+N-1)].sum()
    total_dist.append(temp_total_dist)

print(min(total_dist))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for _ in range(len(a)-1):
    if diff < abs(a[_]-a[_+1]):
        diff = abs(a[_]-(a[_+1]))

if diff < k - abs(a[0]-a[len(a)-1]):
    diff = abs(a[0]-a[len(a)-1])

print(k-diff)

Submission status: Wrong Answer

Solution code:
# 初期入力
K,N = (int(x) for x in input().split(" "))
A = list(map(int, input().split()))
A.append(0) # 基準地点を最後に追加、スタートが０でもうまくいく

# 1件となりまでの距離
kyori = [ A[i+1] -A[i] for i,v in enumerate(A[:-1]) ]
kyori[-1] = kyori[-1] + K # 最後の家は全体から「引く」
kyori.append(A[0] -A[-1] ) # 基準から1番目までの距離
x_saisyo_saigo = kyori[0] +kyori[-1]
kyori.append(x_saisyo_saigo)

# 最短距離は、全体からmax(隣の家との距離)を引く
kyori_min = K - max(kyori)
print(kyori_min)

Submission status: Wrong Answer

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

i=0
m=0
while i < n-1:
  if (a[i+1]-a[i]) > m:
    m=a[i+1]-a[i]
  i += 1

if a[0]==0: 
  a[0]=k
if abs(a[n-1]-a[0]) > m:
  m=abs(a[n-1]-a[0])
print(str(k-m))

Submission status: Wrong Answer

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

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

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

distances = [K-houses[N-1]] + distances
distances.remove(max(distances))

print(sum(distances))

Submission status: Wrong Answer

Solution code:
K,N = map(int,input().split())
A = list(map(int,input().split()))
print(K-(A[N-1]-A[N-2]))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    k,n = LI()
    a = LI()
    flag = False
    for i in range(n):
        if a[i] > k//2:
            flag = False
            a[i] -= k//2
        else:
            flag = True
        if 0 in a:
            a[0] = k//2
    if flag is False:
        print((max(a)-min(a))*2)
    else:
        print(max(a)-min(a))
    return


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

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

rec = list()

rec.append(K - A[-1])

for i, _ in enumerate(A[:-1]):
    rec.append(A[i+1] - A[i])

sum = 0
for r in rec:
    sum += r

max_r = max(rec)
print(sum - max_r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a=list(map(int,input().split()))
l=[]
for i in a:
  for d in a:
    l.append(i-d)
print(k-max(l))

Submission status: Wrong Answer

Solution code:
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l = [abs(a[i-1]-a[i]) for i in range(n)]
print(sum(l) - max(l))

Submission status: Wrong Answer

Solution code:
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(min(k-(a[i-1]-a[i]) for i in range(n)))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    k,n = LI()
    a = LI()
    if 0 in a:
        a[0] = k//2
        print(max(a)-min(a))
    else:
        print(max(a)-min(a))
    return


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
arr=list(map(int,input().split()))
print(max(arr)-min(arr))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    k,n = LI()
    a = LI()
    if 0 in a:
        a.remove(0)
        print(max(a)-min(a))
    else:
        print(max(a)-min(a))
    return


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    k,n = LI()
    a = LI()
    if 0 in a:
        c = a.count(0)
        print(sum(a) // (n-c))
    else:
        print(sum(a) // n)
    return


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
lists = list(map(int, input().split()))
if min(lists)==0:
    aa = K
else:
    aa = min(lists)
lists_k = list([aa])
lists = lists + lists_k
lists_slic = lists[1:] + lists[-1:]
# print(lists)
# print(lists_slic)
a = 0
for i in range(len(lists)):
    if abs(lists[i]-lists_slic[i])>a:
        a = abs(lists[i]-lists_slic[i])

b = K - a

print(b)

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
#a = sorted(a)
b = []
b.append(k-a[-1])

for i in range(n-1):
	b.append(a[i+1]-a[i])
b = sorted(b)
print(sum(b[:-1]))

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
b = []
b.append(k-a[-1])

for i in range(n-1):
	b.append(a[i+1]-a[i])
b = sorted(b)
print(sum(b[:-1]))

Submission status: Wrong Answer

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

lists_slic = lists[-1:] + lists[0:N-1]

# print(lists_slic)
a = 0
for i in range(len(lists)):
    if lists[i] == 0:
        lists[i] = K
    if abs(lists[i]-lists_slic[i])>a:
        a = abs(lists[i]-lists_slic[i])

b = K - a

print(b)

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []
b.append(k-a[-1])

for i in range(n-1):
	b.append(a[i+1]-a[i])
b = sorted(b)
print(sum(b[:-1]))

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []
b.append(k-a[-1])

for i in range(n-1):
	b.append(a[i+1]-a[i])
a = sorted(a)
print(sum(b[:-1]))

Submission status: Wrong Answer

Solution code:
k,n = input().split()
k,n = int(k),int(n)
A = list(map(int,input().rstrip().split()))
s = k+1
m = 0
for i in range(len(A)):
  if(A[i]>m):
    m = A[i]
  if(A[i]<s):
    s = A[i]
print(int(m-s))

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
a = list(map(int,input().split()))
a.append(k-a[-1])
a = sorted(a)
print(sum(a[:-1]))

Submission status: Wrong Answer

Solution code:
k,n = map(int,input().split())
l = list(map(int,input().split()))
m = 0
for i in range(n):
    if i == n-1:
        x = abs(l[0]-l[i])

    else:
        x = l[i+1]-l[i]

    if x > m:
        m = x

print(k-m)

Submission status: Wrong Answer

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

m = 0
for i in range(n):
    if i == n-1:
        x = abs(l[0]-l[i])

    else:
        x = l[i+1]-l[0]

    if x > m:
        m = x

print(k-m)

Submission status: Wrong Answer

Solution code:
import sys
K,N=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

L=[]
prev=None
for a in A:
    if prev is None:
        prev=a
    else:
        L.append(a-prev)
        prev=a
else:
    L.append(K-a)

L.sort()
print sum(L[:-1])

Submission status: Wrong Answer

Solution code:
def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1]-A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    if (K-(se)) > mx:
        mx = K - se
    print(mx)
main()

Submission status: Wrong Answer

Solution code:
import sys
K,N=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

L=[]
prev=None
for a in A:
    if prev is None:
        prev=a
    else:
        L.append(a-prev)
        prev=a
else:
    L.append(K-a)

L.sort()
print sum(L[::-2])

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
p, n = map(int,input().split())
l = list(map(int,input().split()))
ans = min(max(l)-min(l), p-max(l)+ min(l))

Submission status: Wrong Answer

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

s = 0
for i in range(n):
    s += a[i + 1] - a[i]
ans = s
for i in range(n):
    ans = min(ans, s - a[i + 1] + a[i])

print(ans)

Submission status: Wrong Answer

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

s = 0
for i in range(n):
    s += a[i + 1] - a[i]
ans = s
for i in range(n):
    ans = min(ans, s - a[i + 1] - a[i])

print(ans)

Submission status: Wrong Answer

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, m = input_list()
  a = input_list()
  b = []
  for i in range(m):
    if i == 0:
      b.append((n - a[-1]) + a[0])
      continue
    b.append(a[i] - a[i-1])
  print(b)
  bm = max(b)
  print(sum(b) - bm)
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)

Submission status: Wrong Answer

Solution code:
K_N_nyuryoku = input().split()
K = int(K_N_nyuryoku[0])
N = int(K_N_nyuryoku[1])

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)

Submission status: Wrong Answer

Solution code:
K_N_nyuryoku = input().split()
K = K_N_nyuryoku[0]
N = K_N_nyuryoku[1]

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

ans_a = 0
for i in range(len(a)-1):
    ans_a +=(a[i+1]-a[i])
for i in range(n):
    if a[i]>k/2:
        a[i] = k-a[i]

a.sort(reverse=True)
kai = a[0]+a[1]
#print(kai,ans_a)
print(min(kai,ans_a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(K-l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return list(map(str, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n, m = input_list()
  a = input_list()
  b = []
  for i in range(m):
    if i == 0:
      b.append(a[-1] - a[0])
      continue
    b.append(a[i] - a[i-1])
  bm = max(b)
  print(sum(b) - bm)
import math
import fractions
import collections
import itertools
from functools import reduce
main()

Submission status: Wrong Answer

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

dis=[]

for i in range(n):
    if a[i]==a[n-1]:
        dis.append(k-abs(a[i]-a[0]))
    else:
        dis.append(k-abs(a[i]-a[i+1]))
print(dis)
print(min(dis))

Submission status: Wrong Answer

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

dis=[]

for i in range(n):
    if a[i]==a[n-1]:
        dis.append(k-abs(a[0]-a[i]))
    else:
        dis.append(k-abs(a[i+1]-a[i]))
print(dis)
print(min(dis))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
if (A[N-1] - A[0]) > (K+A[0] - A[N-1]):
    A = [x+K if x <= A[N-1]/2 else x for x in A]

print(max(A) - min(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = max(a) - min(a)
for i, num in enumerate(a):
    if num>(k/2):
        a[i] = num - k

print(min(ans,max(a) - min(a)))

Submission status: Wrong Answer

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

A_length_max = K-A[N-1]+A[0]
for i in range (N-2):
    A_length_max=max(A_length_max, A[i+1]-A[i])
print(K-A_length_max)

Submission status: Wrong Answer

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

for i, num in enumerate(a):
    if num>(k/2):
        a[i] = num - k

print(max(a) - min(a))

Submission status: Wrong Answer

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

a.append(k)

diff = []

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

ans = sum(diff) - max(diff)
print(ans)

Submission status: Wrong Answer

Solution code:
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
if (A[N-1] - A[N-2]) > (K - A[N-1]):
    A = [x+K if x != A[N-1] else x for x in A]

print(max(A) - min(A))

Submission status: Wrong Answer

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

print(a[-1]-a[0])

Submission status: Wrong Answer

Solution code:
k,_,*a=map(int,open(0).read().split());a.append(k);b=[y-x for x,y in zip(a,a[1:])];print(sum(b)-max(b))

Submission status: Wrong Answer

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

dis=[]

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

print(min(dis))

Submission status: Wrong Answer

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

a.append(k)

diff = []

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

diff.remove(max(diff))

ans = 0
for d in diff:
    ans += d

print(ans)

Submission status: Wrong Answer

Solution code:
K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
if A[0] == 0 and (A[N-1] - A[N-2]) > (K - A[N-1]):
    A = [x+K if x != A[N-1] else x for x in A]

print(max(A) - min(A))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(K)
A = sorted(A)
l = len(A)
B = []
for i in range(l-1):
  b = abs(A[i+1] - A[i])
  B.append(b)
x = sum(B) - max(B)
y = K - max(B)
if x <= y:
  print(x)
else:
  print(y)

Submission status: Wrong Answer

Solution code:
import numpy as np

k, n = [int(i) for i in input().split()]
a = np.array([int(i) for i in input().split()])

b = np.min(a)

print(np.max(a-b))

Submission status: Wrong Answer

Solution code:
syu,n=map(int,input().split())
a=[int(i) for i in input().split()]
clock=a[n-1]-a[0]
han_clock=min(a[n-2]-a[0],(a[n-1]-a[1]))+(a[0]+syu-a[n-1])
print(min(clock,han_clock))

Submission status: Wrong Answer

Solution code:
e = list(map(int,input().split()))
K = e[0]
N = e[1]
a = list(map(int,input().split()))
c = [a[i+1] - a[i] for i in range(N-1)]
f = a[0]+20 - a[N-1]
c.append(f)
d = max(c)
print(c)
print(d)
print(K - d)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
k,n=map(int,input().split())
a=[int(x) for x in input().split()]
a.sort()
print(min(a[n-1]-a[0],k-a[n-1]+a[n-2]))

Submission status: Wrong Answer

Solution code:
e = list(map(int,input().split()))
K = e[0]
N = e[1]
a = list(map(int,input().split()))
c = [a[i+1] - a[i] for i in range(N-1)]
f = abs(a[N-1] - a[0])
c.append(f)
d = max(c)
print(K - d)

Submission status: Wrong Answer

Solution code:
import numpy as np
K, N = map(int, input().split())
A = np.array(list(map(int, input().split())))
diff = A[1:] - A[:-1]
diff = np.append(diff, K + A[0] - A[-1])
print('diff', diff)
ans = diff.sum() - diff.max()
print(ans)

Submission status: Wrong Answer

Solution code:
K,N=list(map(int,input().split()))
A=list(map(int,input().split()))
ans=0
t=[]
s=K/2
for i in range(N):
    t.append(A[i]-s)
ans=K-max(t)*2
ans1=max(A)-min(A)
if ans>ans1:
    print(int(ans1))
else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(K)
A = sorted(A)
l = len(A)
B = []
for i in range(l-1):
  b = abs(A[i+1] - A[i])
  B.append(b)
x = max(B)
y = sum(B)
z = y - x
print(z)

Submission status: Wrong Answer

Solution code:
import numpy as np
K, N = map(int, input().split())
A = np.array(list(map(int, input().split())))
diff = A[1:] - A[:-1]
diff = np.append(diff, K - A[-1])
# print('diff', diff)
ans = diff.sum() - diff.max()
print(ans)

Submission status: Wrong Answer

Solution code:
syu,n=map(int,input().split())
a=[int(i) for i in input().split()]
clock=a[n-1]-a[0]
han_clock=min(a[1]-a[0],(a[n-1]-a[1]))+(a[0]+syu-a[n-1])
print(min(clock,han_clock))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
K, N = map(int, input().split())
A = list(map(int, input().split()))
# print(K, N)
# print("A:", A)
A = A + [K + A[0]]
# print("A:", A)

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

Submission status: Wrong Answer

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

A.sort()
cur = A[0]
ans1 = 0
for ai in A[1:]:
    ans1 += ai - cur
    cur = ai

A2 = []
for ai in A:
    d2 = ai - K
    if ai <= abs(d2):
        A2.append(ai)
    else:
        A2.append(d2)

A2.sort()
if A2[0] < 0:
    A2 = [i + abs(A2[0]) for i in A2]

cur = A2[0]
ans2 = 0
for ai in A2[1:]:
    ans2 += ai - cur
    cur = ai

# print(ans1, ans2)
ans = min(ans1, ans2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K, N = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
l = len(A)
B = list(map(lambda x: K - x, A))
B = sorted(B)
C = []
for i in range(l):
  c = abs(A[i] - B[i])
  C.append(c)
c_min = min(C)
if c_min == 0:
  print(max(A) - min(A))
else:
  print(K - c_min)

Submission status: Wrong Answer

Solution code:
k,n = map(int, input().split())
l = list(map(int, input().split()))
d = []
for i in range(n):
  if i + 1 < n:
    d.append(l[i+1]-l[i])
  else:
    d.append(k - l[i])
sum = sum(d)
a = []
for i in range(n):
  a.append(sum - d[i])
print(min(a))

Submission status: Wrong Answer

Solution code:
syu,n=map(int,input().split())
a=[int(i) for i in input().split()]
clock=a[n-1]-a[0]
han_clock=(a[n-1]-a[1])+(a[0]+syu-a[n-1])
print(min(clock,han_clock))

Submission status: Wrong Answer

Solution code:

KN = input("").split()
A = input("").split()

K = int(KN[0])
N = int(KN[1])
A_0 = int(A[0])
A_N = int(A[N-1])
L = A_0

for j in range(N-1):
    A_i = int(A[j+1])
    A_m = int(A[j])
    if A_i - A_m > L:
        L = A_i - A_m

if L > K - A_N + A_0:
    print(K-L)
else:
    print(K - A_N + A_0)

Submission status: Wrong Answer

Solution code:
def main():
    K, N = map(int, input().split(' '))
    half_k = K // 2
    A = list(map(int, input().split()))
    A.sort()
    A.append(A[0] + K)
    max_diff = A[-1] - half_k + A[0]
    for n in range(0, N - 1, 2):
        if max_diff < A[n + 1] - A[n]:
            max_diff = A[n + 1] - A[n]
    print(K - max_diff)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
syu,n=map(int,input().split())
a=[int(i) for i in input().split()]
clock=a[n-1]-a[0]
han_clock=(a[n-2]-a[1])+(a[0]+syu-a[n-1])
print(min(clock,han_clock))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
K, N = map(int, input().split())
A = list(map(int, input().split()))

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

Submission status: Wrong Answer

Solution code:
k,n = map(int, input().split())
l = list(map(int, input().split()))
d = []
for i in range(n):
  if i + 1 < n:
    d.append(l[i+1]-l[i])
  else:
    d.append(k - l[i])
sum = sum(d)
a = []
for i in range(n-1):
  a.append(sum - d[i])
print(min(a))

Submission status: Wrong Answer

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

a = [0]*N
for i in range(N):
    r = (A[i+1] if i+1 < len(A) else A[0])
    if r == 0:
        a[i] = min(abs(r - A[i]), abs(K - A[i]))
    else:
        a[i] = abs(r - A[i])
a.sort()

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

print(d)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

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

house_list = list(map(int, input().split()))
#print(house_list)

dist_list = [ (K -house_list[-1]) + house_list[0]]
#print(dist_list)

for n in range(1, N):
    dist_list.append(house_list[n] - house_list[n-1])
print(max(dist_list))

Submission status: Wrong Answer

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)

#入力
k,n = map(int,input().split())
a = list(map(int,input().split()))
diff = []
for i in range(len(a)):
    d = abs(a[i-1] - a[i])
    diff.append(d)
diff.sort()
print(k-diff[-1])
#解答
#出力

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
readline = sys.stdin.buffer.readline
K, N = map(int, readline().split())
A = list(map(int,input().split()))
N1= A[N-1]-K
L1=abs(N1)+A[N-2]
L2=A[N-1]-A[0]
c = min(L1,L2)
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np
k, n = map(int, input().split())
a = np.array(list(map(int, input().split())))
maxi = -1
for i in range(0, len(a)-1):
    tmp = max(abs(a[i] - a[i-1]), abs(a[i] - a[i+1]))
    if maxi == -1:
        maxi = tmp
    else:
        maxi = max(maxi, tmp)
print(k - maxi)