Problem:


Score : 500 points

Problem Statement

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.

Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:

Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.

The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.

X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints

All input values are integers.

1 \leq N \leq 2000

1 \leq Z, W, a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

If X draws all the cards first, the score will be |1000 - 100| = 900.

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999



Sample input:
3 100 100
10 1000 100


Sample output:
900

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
  print(abs(a[0]-w))
else:
  b=[w]+a[:n-1]
  ans=-1
  for i in b:
    if abs(a[-1]-i)>ans:ans=abs(a[-1]-i)
  for i in range(1,n):
    if abs(a[-1]-i)>ans:ans=abs(a[-1]-i)
  print(ans)

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
  print(abs(a[0]-w))
else:
  b=[w]+a[:n-1]
  ans=-1
  for i in b:
    if abs(a[-1]-i)>ans:ans=abs(a[-1]-i)
  for i in range(1,n):
    if abs(a[-1]-i)>ans:ans=abs(a[-1]-i)

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
a+=[w]
a.sort()
print(max(a)-min(a))

Submission status: Wrong Answer

Solution code:
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
b = abs(W-A[-1])
for i in range(N-1):
    b = max(b,abs(A[i]-A[-1]))
print(b)

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
  print(abs(a[0] - w))
else:
  print(max(a[-1] - w, a[-1] - a[-2]))

Submission status: Wrong Answer

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

#i+1枚引くとする
#Xはスコアの最小値を最大化したい
min_score = [0]*n
for i in range(n):
  if i == n-1:
    min_score[i] = abs(l[n-1]-w)
    break
  temp = l[i]
  temp_min = 10**9+1
  for j in range(i+1, n):
    if abs(temp-l[j]) <= temp_min:
      temp_min = abs(temp-l[j])
  min_score[i] = temp_min
print(max(min_score))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC78 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
que = deque(a)
tmp1 = que.popleft()
tmp2 = w
turn = 0
cnt = 0
while que:
    if turn == 0:
        if tmp1 <= que[0]:
            tmp1 = que.popleft()
            cnt += 1
        else:
            if cnt > 0:
                turn = 1
                cnt = 0
            else:
                tmp1 = que.popleft()
                turn = 1
    else:
        if tmp2 >= que[0]:
            tmp2 = que.popleft()
            cnt += 1
        else:
            if cnt > 1:
                turn = 0
                cnt = 0
            else:
                tmp2 = que.popleft()
                turn = 0
print(abs(tmp1-tmp2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC78 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,z,w = LI()
a = LI()
que = deque(a)
tmp1 = que.popleft()
tmp2 = w
turn = 0
cnt = 0
while que:
    if turn == 0:
        if tmp1 <= que[0]:
            tmp1 = que.popleft()
        else:
            turn = 1
    else:
        if tmp2 >= que[0]:
            tmp2 = que.popleft()
        else:
            turn = 0
    cnt += 1
    if cnt > n:
        print(abs(tmp1 - tmp2))
        quit()
print(abs(tmp1-tmp2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n,z,w = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  if n == 1:
    ans = abs(w-a[0])
  else:
    ans = 0
    for i in range(n):
      #最小化する方向に動く
      tmp = abs(a[i]-a[n-1])
      tmp2 = abs(a[n-1]-w)
      ans = max(tmp,tmp2)
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def solve():
  n,z,w = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  if n == 1:
    ans = abs(w-a[0])
  else:
    ans = 0
    for i in range(n):
      if i != n-1:
        tmp = abs(a[i]-a[n-1])
      else:
        tmp = abs(a[n-1]-w)
      ans = max(ans,tmp)
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
N,Z,W,*A=map(int,open(0).read().split());print(max(max(A)-A[-1],A[-1]-min(A),abs(A[-1]-W)))

Submission status: Wrong Answer

Solution code:
N, Z, W = map(int, input().split())
a = [int(i) for i in input().split()]

m, M = min([W]+a), max([W]+a)
print(max(abs(a[-1]-m), abs(a[-1]-M)))

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
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)]
mod = 1000000007

#A
"""
x, y = LS()
if x > y:
    print(">")
elif x == y:
    print("=")
else:
    print("<")
"""

#B
"""
x, y, z = LI()
print((x-z)//(y+z))
"""

#C
"""
n, m = LI()
print((m*1900+(n-m)*100)*2**m)
"""

# D
# 解説AC
# 山札のどれからとってもいいという話ではないのか！！！！
n, z, w = LI()
a = LI()
if n == 1:
    print(abs(a[0] - w))
else:
    print(min(abs(a[-1] - w), abs(a[-1] - a[-2])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,z,w = map(int,input().split())
a = [z] + list(map(int,input().split())) + [w]


'''
for i in range(1,n+1):
    ans = max(ans,min(list(map(lambda x: abs(x-a[i]), a[i+1:]))))
'''


print(max( abs(a[n-1]-a[n]),abs(a[n]-a[n+1])  ))

Submission status: Wrong Answer

Solution code:
n,z,w = map(int,input().split())
a = [0] + list(map(int,input().split())) + [w]


ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,z,w = map(int,input().split())
a = [0] + list(map(int,input().split())) + [w]


ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    A_max = max(A)
    A_min = min(A)
    
    tmp2 = abs(A[-1] - W)
    tmp3 = 0
    if A_max != A[-1]:
        tmp3 = abs(A_max - A[-1])
    tmp4 = 0
    if A_min != A[-1] and A_min != A[0]:
        tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max != A[-1] and A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    print(max(tmp2, tmp3, tmp4, tmp5))
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    A_max = max(A)
    A_min = min(A)
    
    tmp2 = abs(A[-1] - W)
    tmp3 = 0
    if A_max != A[-1]:
        tmp3 = abs(A_max - A[-1])
    tmp4 = 0
    if A_min != A[-1]:
        tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max != A[-1] and A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    print(max(tmp2, tmp3, tmp4, tmp5))
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    A_max = max(A)
    A_min = min(A)
    
    ans = 0
    tmp1 = abs(Z - A[-1])
    tmp2 = abs(A[-1] - W)
    tmp3 = abs(A_max - A[-1])
    tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max == A[-1] or A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    tmp6 = 0
    for i in range(N-1):
        tmp = abs(A[i] - A[-1])
        tmp6 = max(tmp6, tmp)
        
    tmp7 = 0
    for i in range(N-1):
        tmp = abs(A[-1] - A[i])
        tmp7 = max(tmp7, tmp)
    
    print(max(tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7))
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    A_max = max(A)
    A_min = min(A)
    
    ans = 0
    tmp1 = abs(Z - A[-1])
    tmp2 = abs(A[-1] - W)
    tmp3 = abs(A_max - A[-1])
    tmp4 = abs(A[-1] - A_min)
    
    tmp5 = 0
    if A_max == A[-1] or A_min == A[-1]:
        tmp5 = abs(A_max - A_min)
    
    print(max(tmp1, tmp2, tmp3, tmp4, tmp5))
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,Z,W = inputMap()
    A = inputList()
    
    A_max = max(A)
    A_min = min(A)
    
    ans = 0
    tmp1 = abs(Z - A[-1])
    tmp2 = abs(A[-1] - W)
    tmp3 = abs(A_max - A[-1])
    tmp4 = abs(A[-1] - A_min)
    
    print(max(tmp1, tmp2, tmp3, tmp4))
            	
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def method_1(N, Z, W, a):
    return abs(a[-1]-W)


def method_2(N, Z, W, a):
    return abs(max(a[0:-1])-a[-1])


def method_3(N, Z, W, a):
    return abs(min(a[1:-1])-a[-1])


def solve(N: int, Z: int, W: int, a: "List[int]"):
    res = 0
    
    res = max(res,method_1(N,Z,W,a))
    if N >= 2:
        res = max(res,method_2(N,Z,W,a))
    if N >= 3:
        res = max(res,method_1(N,Z,W,a))

    print(res)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, Z, W, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def myindex(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
n=len(a)
k=0
x=z
y=w
while k<n:
  new_x=0
  new_y=1000000001
  for i in range(n):
    new_x=max(new_x,abs(y-a[i]))
  k=min(myindex(a,y-new_x),myindex(a,y+new_x))
  x=a[k]      
  a=a[k+1:]
  n=len(a)
  if a!=[]:  
    for i in range(n):
      new_y=min(new_y,abs(x-a[i]))
    k=min(myindex(a,x-new_y),myindex(a,x+new_y))
    y=a[k]
    a=a[k+1:]
    n=len(a)
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
def main():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    i = 0
    tz = Z
    tw = W

    while N > i + 1:
        d = 0
        for j in range(i, N):
            if abs(a[j] - tw) > d:
                d = abs(a[j] - tw)
                tz = a[j]
                i = j + 1
        d = float('INF')
        for k in range(i, N):
            if d > abs(a[k] - tz):
                d = abs(a[k] - tz)
                tw = a[k]
                i = k + 1

    print(max(abs(tz - tw), abs(W - a[-1])))


main()

Submission status: Wrong Answer

Solution code:
N,Z,W=map(int, input().split())
INL = list(map(int,input().split()))
# INVL = {v:i for i, v in enumerate(INL)}

class BitMAX:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = max(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

class BitMIN:
    def __init__(self, n):
        self.size = n
        self.tree = [10**9+1] * (n + 1)
 
    def sum(self, i):
        s = 10**9+1
        while i > 0:
            s = min(self.tree[i], s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

bit_max = BitMAX(3000)
bit_min = BitMIN(3000)

offset = 2500

for i, v in enumerate(INL):
    bit_max.add(offset-i, v)
    bit_min.add(offset-i, v)

res = 0
for i in range(N-1):
    ma = abs(bit_max.sum(offset-i) - bit_max.sum(offset-i-1))
    mi = abs(bit_min.sum(offset-i) - bit_min.sum(offset-i-1))
    res = max(res, ma, mi)

print(max(res, abs(INL[-1]-W)))

Submission status: Wrong Answer

Solution code:
N,Z,W=map(int, input().split())
INL = list(map(int,input().split()))
INVL = {v:i for i, v in enumerate(INL)}

class BitMAX:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = max(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

class BitMIN:
    def __init__(self, n):
        self.size = n
        self.tree = [10**9+1] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = min(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

bit_max = BitMAX(3000)
bit_min = BitMAX(3000)

offset = 2500

for i, v in enumerate(INL):
    bit_max.add(offset-i, v)
    bit_min.add(offset-i, v)

pos = 0
while pos < len(INL):
    ma = bit_max.sum(offset-pos)
    mi = bit_min.sum(offset-pos)
    if abs(W-ma) > abs(W-mi):
        Z = ma
        pos = INVL[ma]+1
    else:
        Z = mi
        pos = INVL[mi]+1
    # print("A pos: {}".format(pos))

    if pos < len(INL):
        ma = bit_max.sum(offset-pos)
        mi = bit_min.sum(offset-pos)
        if abs(Z-ma) < abs(Z-mi):
            W = ma
            pos = INVL[ma]+1
        else:
            W = mi
            pos = INVL[mi]+1
        # print("B pos: {}".format(pos))

print(abs(Z-W))

Submission status: Wrong Answer

Solution code:
N,Z,W=map(int, input().split())
INL = list(map(int,input().split()))
INVL = {v:i for i, v in enumerate(INL)}

class BitMAX:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = max(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

class BitMIN:
    def __init__(self, n):
        self.size = n
        self.tree = [10*9] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = min(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

bit_max = BitMAX(3000)
bit_min = BitMAX(3000)

offset = 2500

for i, v in enumerate(INL):
    bit_max.add(offset-i, v)
    bit_min.add(offset-i, v)

pos = 0
while pos < len(INL):
    ma = bit_max.sum(offset-pos)
    mi = bit_min.sum(offset-pos)
    if abs(W-ma) > abs(W-mi):
        Z = ma
        pos = INVL[ma]+1
    else:
        Z = mi
        pos = INVL[mi]+1
    # print("A pos: {}".format(pos))

    if pos < len(INL):
        ma = bit_max.sum(offset-pos)
        mi = bit_min.sum(offset-pos)
        if abs(Z-ma) < abs(Z-mi):
            W = ma
            pos = INVL[ma]+1
        else:
            W = mi
            pos = INVL[mi]+1
        # print("B pos: {}".format(pos))

print(abs(Z-W))

Submission status: Wrong Answer

Solution code:
N,Z,W=map(int, input().split())
INL = list(map(int,input().split()))
INVL = {v:i for i, v in enumerate(INL)}

class BitMAX:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = max(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = max(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

class BitMIN:
    def __init__(self, n):
        self.size = n
        self.tree = [10*9] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s = min(self.tree[i],s)
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] = min(x, self.tree[i])
            i += i & -i
    
    def reset(self):
        t = self.tree
        for i in range(len(t)):
            t[i] = 0

bit_max = BitMAX(3000)
bit_min = BitMAX(3000)

offset = 2500

for i, v in enumerate(INL):
    bit_max.add(offset-i, v)
    bit_min.add(offset-i, v)

pos = 0
while pos < len(INL):
    ma = bit_max.sum(offset-pos)
    mi = bit_min.sum(offset-pos)
    if abs(Z-ma) > abs(Z-mi):
        Z = ma
        pos = INVL[ma]+1
    else:
        Z = mi
        pos = INVL[mi]+1
    # print("A pos: {}".format(pos))

    if pos < len(INL):
        ma = bit_max.sum(offset-pos)
        mi = bit_min.sum(offset-pos)
        if abs(W-ma) < abs(W-mi):
            W = ma
            pos = INVL[ma]+1
        else:
            W = mi
            pos = INVL[mi]+1
        # print("B pos: {}".format(pos))

print(abs(Z-W))

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    
    n,z,w,*a=map(int,open(0).read().split())
    if n==1:
        print(abs(a[n-1]-w))
    else:
        print(abs(max(a[n-1]-w,a[n-2]-w)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    
    n,z,w,*a=map(int,open(0).read().split())
    if n==1:
        print(a[n-1]-w)
    else:
        print(max(a[n-1]-w,a[n-2]-w))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    
    n,z,w,*a=map(int,open(0).read().split())
    print(abs(max([a[-1]-min(a[1:-1]or[-float("inf")]),max(a[:-1]or[-float("inf")])-a[-1]]+[w-a[-1]]+[a[-1]-w]+[a[i]-a[-1]for i in range(n-1)]+[-a[i]+a[-1]for i in range(1,n-1)])))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    
    n,z,w,*a=map(int,open(0).read().split())
    print(max([a[-1]-min(a[1:-1]or[0]),max(a[:-1]or[0])-a[-1]]+[w-a[-1]]+[a[-1]-w]+[a[i]-a[-1]for i in range(n-1)]+[-a[i]+a[-1]for i in range(1,n-1)]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    
    n,z,w,*a=map(int,open(0).read().split())
#    if len(a)>10:
#        print(a[-1]-min(a),max(a)-a[-1])
#        
#    else:
    print(max([a[-1]-w]+[a[i]-a[-1]for i in range(n-1)]+[-a[i]+a[-1]for i in range(1,n-1)]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N, Z, W = MI()
    A = LI()
    
    lm = Z
    left_maxims = [Z]
    for l in range(N):
        left_maxims.append(max(Z, A[l]))

    rm=W
    right_maxims = [W]
    for r in range(N):
        right_maxims.append(max(Z, A[r]))
    ans=0
    for l in range(N + 1):
        ans = max(ans,abs(left_maxims[l] - right_maxims[-1 - l]))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# Xが引いた枚数を固定するとスコアが確定

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

X_score = [Z] + A
Y_score = [None] * N + [W]
for n in range(N-1,-1,-1):
  Y_score[n] = max(Y_score[n+1], A[n])

answer = Z-W
for x,y in zip(X_score,Y_score):
  answer = max(answer, x-y)

print(answer)

Submission status: Wrong Answer

Solution code:
# Xが引いた枚数を固定するとスコアが確定

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

X_score = [Z] + A
Y_score = [None] * N + [W]
for n in range(N-1,-1,-1):
  Y_score[n] = min(Y_score[n+1], A[n])

answer = Z-W
for x,y in zip(X_score,Y_score):
  answer = max(answer, x-y)

print(answer)

Submission status: Wrong Answer

Solution code:
import functools
import os
import sys
import numpy as np


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        ret = fn(*args, **kwargs)
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        print(ret)
        return ret

    return wrapper


sys.setrecursionlimit(10000)
INF = float('inf')

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

# def xy(x, y, pos, x_turn):
#     if x_turn:
#         return A[pos], y
#     else:
#         return x, A[pos]
#
#
# @debug
# def solve(x, y, pos, x_turn):
#     if pos >= N:
#         return abs(x - y)
#
#     if x_turn:
#         ans = -INF
#         for i in range(pos, N):
#             x, y = xy(x, y, i, x_turn)
#             ans = max(ans, solve(x, y, i + 1, not x_turn))
#     else:
#         ans = INF
#         for i in range(pos, N):
#             x, y = xy(x, y, i, x_turn)
#             ans = min(ans, solve(x, y, i + 1, not x_turn))
#     return ans
#
# print(solve(Z, W, 0, True))


# @lru_cache(maxsize=None)
# def dpx(i):
#     """
#     i 番目から x が最善を尽くしたときのスコア
#     :param i:
#     :return:
#     """
#     if i == 0:
#         y = W
#     else:
#         y = A[i - 1]
#
#     ret = abs(A[-1] - y)
#     for i in range(i + 1, N):
#         ret = max(ret, dpy(i))
#     return ret
#
#
# @lru_cache(maxsize=None)
# def dpy(i):
#     """
#     i 番目から y が最善を尽くしたときのスコア
#     :param i:
#     :return:
#     """
#     if i == 0:
#         x = Z
#     else:
#         x = A[i - 1]
#
#     ret = abs(A[-1] - x)
#     for i in range(i + 1, N):
#         ret = min(ret, dpx(i))
#     return ret


# dpx[i]: i 番目以降から始めて x が最善を尽くしたときの最低スコア
dpx = np.empty(N + 1)
# dpy[i]: i 番目以降から始めて y が最善を尽くしたときの最高スコア
dpy = np.empty(N + 1)

dpx.fill(np.inf)
dpy.fill(-np.inf)
for i in reversed(range(N)):
    y = A[i - 1] if i > 0 else W
    dpx[i] = max(abs(A[-1] - y), dpy[i + 1])

    x = A[i - 1] if i > 0 else Z
    dpy[i] = min(abs(A[-1] - y), dpx[i + 1])

print(int(dpx[0]))

Submission status: Wrong Answer

Solution code:
n,z,w = map(int,input().split())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    if not a[i] in dic.keys():
        dic[a[i]] = 0
    dic[a[i]] = max(dic[a[i]],i)
sorted_a = sorted(list(set(a)))
cnt = -1
while cnt<n-1:
    for x in range(len(sorted_a)-1,-1,-1):
        k = sorted_a[x]
        if dic[k]>cnt:
            cnt = dic[k]
            z = k
            break
    if cnt==n-1:
        break
    for y in range(len(sorted_a)):
        k = sorted_a[y]
        if dic[k]>cnt:
            cnt = dic[k]
            w = k
            break
print(abs(z-w))