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: Accepted

Solution code:
def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    if N == 1:
        return abs(A[-1] - W)
    return max(abs(A[-1] - W), abs(A[-1] - A[-2]))


print(main())

Submission status: Accepted

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([abs(a[n-1]-w), abs(a[n-2]-a[n-1])]))

Submission status: Accepted

Solution code:
N,Z,W=map(int,input().split())
alist=list(map(int,input().split()))

if N==1:
  print(abs(alist[-1]-W))
else:
  ans1=abs(alist[-2]-alist[-1])
  ans2=abs(alist[-1]-W)
  print(max(ans1,ans2))

Submission status: Accepted

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

if n >= 2:

    # xがaiをとったときにyが最適に行動した時のスコア
    dp_x = [abs(a[-1] - a[i]) for i in range(n)]
    # yがaiをとったときにxが最適に行動した時のスコア
    dp_y = [abs(a[-1] - a[i]) for i in range(n)]

    for i in reversed(range(n-1)):
        for j in range(i):
            dp_x[j] = min(dp_x[j], dp_y[i])
            dp_y[j] = max(dp_y[j], dp_x[i])

    print(max(abs(a[-1]-w), max(dp_x)))
else:
    print(abs(a[-1]-w))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,z,w = na()
a = na()

if n == 1:
    print(abs(a[-1]-w))
    exit()

print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

Submission status: Accepted

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(abs(A[-1] - w), abs(A[-2] - A[-1])))

Submission status: Accepted

Solution code:
N,Z,W =  map(int,input().split(" "))        # Z は要らん子
 
a = list(map(int,input().split(" ")))
 
if N == 1:
	ans = abs(a[-1]-W)
else:
	ans = max(abs(a[-1]-a[-2]),abs(a[-1]-W))
 
 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution

import io
import math
import scipy.sparse

nim,mike,kite = map(int, input().split())

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

print(max(abs(kite-array[nim-1]), abs(array[nim-1]-array[nim-2])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, Z, W = map(int, input().split())
    A = [int(a) for a in input().split()]
    if N == 1: print(abs(W - A[0]))
    else: print(max(abs(W - A[N-1]), abs(A[N-2] - A[N-1])))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

if N == 1:
    ans = abs(A[0] - W)
else:
    # 1枚残す場合
    ans = abs(A[-1] - A[-2])
    # 0枚残す場合
    ans = max(ans, abs(A[-1] - W))

print(ans)

Submission status: Accepted

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(abs(a[n-2]-a[n-1]), abs(w-a[n-1])))

Submission status: Accepted

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(abs(A[-1] - W), abs(A[-2] - A[-1])))

Submission status: Accepted

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(abs(A[-1] - W), abs(A[-1] - A[-2])))

Submission status: Accepted

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

Submission status: Accepted

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(abs(A[-1]-w), abs(A[-2]-A[-1])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, Z: int, W: int, a: "List[int]"):
    dp = [(0, 0)] * N
    if N == 1:
        dp[N - 1] = (abs(a[N - 1] - W), abs(Z - a[N - 1]))
    else:
        dp[N - 1] = (abs(a[N - 1] - a[N - 2]), abs(a[N - 2] - a[N - 1]))
    for i in reversed(range(N - 1)):
        v1 = max(dp[j][1] for j in range(i + 1, N))
        if i == 0:
            v1 = max(v1, abs(a[N - 1] - W))
        else:
            v1 = max(v1, abs(a[N - 1] - a[i - 1]))
        v2 = min(dp[j][0] for j in range(i + 1, N))
        if i == 0:
            v2 = min(v2, abs(Z - a[N - 1]))
        else:
            v2 = min(v2, abs(a[i - 1] - a[N - 1]))
        dp[i] = (v1, v2)
    print(dp[0][0])


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: Accepted

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
print(max(abs(W-a[-1]),abs(a[N-1]-a[N-2])))

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

ans = abs(W - a[-1])
if N > 1:
    ans = max(ans, abs(a[-2] - a[-1]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, Z, W = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    ans = abs(A[-1] - W)
    if N > 1:
        ans = max(abs(A[-2] - A[-1]), ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

dp = [0] * N
ep = [0] * N
# ある地点まで来た時その人は一個前の数を持っている
#print(A)
#print(W - A[-1])
for i in range(N-1,-1,-1):
    # 最後のマスまで行く
    dp[i] = abs( (W if i == 0 else A[i-1]) - A[-1])
    ep[i] = abs( (Z if i == 0 else A[i-1]) - A[-1])
    # それ以外
    for j in range(i + 1, N):
        dp[i] = max(dp[i] , ep[j])
        ep[i] = min(ep[i] , dp[j])
#print(dp)
#print(ep)
print(dp[0])

Submission status: Accepted

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(abs(a[-1]-W), abs(a[-1] - a[-2])))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(a[-1] - W)
if N > 1:
    ans = max(ans, abs(a[-2] - a[-1]))
print(ans)

Submission status: Accepted

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

if N == 1:
    print(abs(A[0] - W))
    exit()

print(max(abs(A[-1] - W), abs(A[-2] - A[-1])))

Submission status: Accepted

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

if n == 1:
    print(abs(w - a[-1]))
    exit()
print(max(abs(w - a[-1]), abs(a[-1] - a[-2])))

Submission status: Accepted

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N,Z,W = map(int, input().split())
    a = list(map(int, input().split()))
    if N>=2:
        print(max(abs(a[-1]-W), abs(a[-1]-a[-2])))
    else:
        print(abs(a[0]-W))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MAXN = 2005

dp0 = [[-1] * MAXN for _ in range(MAXN)]
dp1 = [[-1] * MAXN for _ in range(MAXN)]

def dfs(i,j,p,z,w,a,n):
    if p == 0:
        if dp0[i][j] != -1:
            return dp0[i][j]
        if i == n:
            if j == 0:
                return abs(w - a[-1])
            return abs(a[j -1] - a[-1])
        ans = 0
        for k in range(i,n):
            ans = max(ans,dfs(k + 1,k,1,z,w,a,n))
        if i == 1:
            ans = max(ans,abs(a[-1] - w))
        else:
            ans = max(ans,abs(a[-1]- a[i - 1]))
        dp0[i][j] = ans
        return ans
    elif p == 1:
        if dp1[i][j] != -1:
            return dp1[i][j]
        if i == n:
            if j == 0:
                return abs(z - a[-1])
            return abs(a[j - 1] - a[-1])
        ans = INF
        for k in range(i,n):
            ans = min(ans,dfs(k + 1,k,0,z,w,a,n))
        if i == 1:
            ans = min(ans,abs(a[-1] - z))
        else:
            ans = min(ans,abs(a[-1] - a[i - 1]))
        dp1[i][j] = ans
        return ans

def main():
    n,z,w = map(int,input().split())
    a = list(map(int,input().split()))

    ans = dfs(1,0,0,z,w,a,n)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

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

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

last = a[-1]

if n == 1:
    print(abs(w-last))
    exit()

last2 = a[-2]

print(max(abs(last2-last), abs(last-w)))

Submission status: Accepted

Solution code:
#難しく考えすぎていた
#こういう問題は最後どうなるかを考える
#最後は結局一番最後のカードを必ず引くことになる
#そのカードをどちらが引くのか
#先攻が圧倒的有利

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

Submission status: Accepted

Solution code:
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
A.append(Z)
A.append(W)


dpx=[[0 for j in range(0,N+2)] for k in range(0,N+1)]
dpy=[[0 for j in range(0,N+2)] for k in range(0,N+1)]

for i in range(0,N+2):
    dpx[N-1][i]=abs(A[N-1]-A[i])
    dpy[N-1][i]=abs(A[N-1]-A[i])


for i in range(1,N):
    for j in range(0,N+2):
        I=N-1-i
        dpx[I][j]=max(dpy[I+1][I],dpx[I+1][j],abs(A[N-1]-A[j]))
        dpy[I][j]=min(dpx[I+1][I],dpy[I+1][j],abs(A[N-1]-A[j]))

print(dpx[0][N+1])

Submission status: Accepted

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))

if N == 1:
    print(abs(W-a[N-1]))
else:
    print(max(abs(W-a[N-1]),abs(a[N-1]-a[N-2])))

Submission status: Accepted

Solution code:
def solve():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    
    if N == 1:
        print(abs(a[0] - W))
        exit()
    
    print(max(abs(a[-1] - W), abs(a[-2] - a[-1])))


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

if n == 1:
    print(abs(w - a[-1]))
    exit()
ans = max(abs(w - a[-1]), abs(a[-1] - a[-2]))
print(ans)

Submission status: Accepted

Solution code:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 10

coef = [-1, 1]
initial = [w, z]
func = [max, min]
turn = [0, 1]

dp = [[None] * 2 for _ in range(n)]
for i in range(n - 1, -1, -1):
    for c, ini, f, t in zip(coef, initial, func, turn):
        dp[i][t] = c * INF
        opo_card = a[i-1] if i else ini
        dp[i][t] = f(dp[i][t], abs(a[-1] - opo_card))
        opo_t = (t + 1) % 2
        for j in range(i + 1, n):
            dp[i][t] = f(dp[i][t], dp[j][opo_t])

ans = dp[0][0]
print(ans)

Submission status: Accepted

Solution code:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
INF = 10 ** 10

dp = [[None] * 2 for _ in range(n)]
for i in range(n - 1, -1, -1):
    dp[i][0] = -INF
    y = a[i-1] if i else w
    dp[i][0] = max(dp[i][0], abs(y - a[-1]))
    for j in range(i + 1, n):
        dp[i][0] = max(dp[i][0], dp[j][1])

    dp[i][1] = INF
    x = a[i-1] if i else z
    dp[i][1] = min(dp[i][1], abs(x - a[-1]))
    for j in range(i + 1, n):
        dp[i][1] = min(dp[i][1], dp[j][0])

ans = dp[0][0]
print(ans)

Submission status: Accepted

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

ans = abs(a[-1] - w)
if n > 1:
    ans = max(ans, abs(a[-2] - a[-1]))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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(abs(a[-1]-W),abs(a[N-2]-a[N-1])))

Submission status: Accepted

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

if n==1:
    print(abs(w-a[0]))
    exit()
print(max(abs(w-a[-1]),abs(a[-1]-a[-2])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))

score = abs(a[-1] - W)

if len(a) >= 2:
    score2 = abs(a[-2] - a[-1])
    score = max(score, score2)

print(score)

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(a[-1] - W)
if N > 1:
    ans = max(ans, abs(a[-2] - a[-1]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
 
if N == 1:
    ans = abs(A[-1] - W)
else:
    ans = max(abs(A[-1] - W), abs(A[-1] - A[-2]))
 
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    N,Z,W=MI()
    a=LI()
    inf=10**10
    
    #xがi枚目,yがj枚目を持っているとき
    dp=[[0]*(N+1) for _ in range(N+1)]
    
    #dpのj列目の,j行目より先の最大値を持っておく
    Mj=[0]*(N+1)
    
    #dpのi行目の,i列めより先の最小値を持っておく
    mi=[inf]*(N+1)
    
    #初期化
    dp[-1][0]=abs(a[-1]-W)
    Mj[0]=abs(a[-1]-W)
    for i in range(1,N):
        dp[i][-1]=abs(a[-1]-a[i-1])
        dp[-1][i]=abs(a[-1]-a[i-1])
        Mj[i]=abs(a[-1]-a[i-1])
        mi[i]=abs(a[-1]-a[i-1])
        
    for i in range(N-1,0,-1):
        for j in range(N-1,-1,-1):
            if i==j:
                continue
            if i>j:
                dp[i][j]=mi[i]
                Mj[j]=max(Mj[j],dp[i][j])
            else:
                dp[i][j]=Mj[j]
                mi[i]=min(mi[i],dp[i][j])
        
    print(Mj[0])
        

main()

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())
a = list(map(int,input().split()))
can = [abs(y-a[-1])]
if n != 1:
  can.append(abs(a[-1]-a[-2]))
print(max(can))

Submission status: Accepted

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

if N == 1:
    ans = abs(A[-1] - W)
else:
    ans = max(abs(A[-1] - W), abs(A[-1] - A[-2]))

print(ans)

Submission status: Accepted

Solution code:
N,Z,W=map(int,input().split())
A=list(map(int,input().split()))
if len(A)==1:
    print(abs(A[0]-W))
else:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def d_abs():
    N, Z, W = [int(i) for i in input().split()]
    A = [W] + [int(i) for i in input().split()]  # こうすると場合分けが不要
    return max(abs(A[N] - W), abs(A[N] - A[N - 1]))

print(d_abs())

Submission status: Accepted

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

if n == 1:
    print(abs(cards[0]-w))
    exit()

pattern1 = abs(cards[-1] - w)  # 初手で全部とる
pattern2 = abs(cards[-2] - cards[-1])  # それ以外

ans = max(pattern1, pattern2)
print(ans)

Submission status: Accepted

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(abs(a[-1]-w),abs(a[-2]-a[-1])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,z,w = inm()
a = inl()
a[0:0] = [w]
f = [0]*n
g = [0]*n
f[n-1] = g[n-1] = minf = maxg = abs(a[n]-a[n-1])
for i in range(n-2,-1,-1):
    f[i] = max(maxg, abs(a[i]-a[n]))
    g[i] = min(minf, abs(a[i]-a[n]))
    minf = min(minf, f[i])
    maxg = max(maxg, g[i])
print(f[0])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

def main():
    N,Z,W = map(int,input().split())
    A = list(map(int,input().split()))
    
    if len(A) != 1:
        a = abs(A[-1]-W)
        b = abs(A[-2]-A[-1])
        print(max(a,b))
    else:
        print(abs(A[0]-W))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,Z,W= map(int,input().split())
A = list(map(int,input().split()))
print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)) if N > 1 else abs(A[-1]-W))

Submission status: Accepted

Solution code:
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N>=2:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))
else:
    print(abs(A[0]-W))

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
    print(abs(A[0]-W))
elif A[-1]==A[-2]:
    print(abs(A[-1]-W))
else:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))

Submission status: Accepted

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

if N == 1:
    print(abs(A[0] - W))
else:
    print(max(abs(A[N-1] - W), abs(A[N-2] - A[N-1])))

Submission status: Accepted

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

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

ans = max(abs(w - a[len(a) - 1]), abs(a[len(a) - 1] - a[len(a) - 2]))

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,Z,W=map(int,input().split())
a=list(map(int,input().split()))
if N==1:
    print(abs(a[-1]-W))
else:
    print(max(abs(a[-1]-W),abs(a[-1]-a[-2])))

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]*2 for _ in range(N+1)]

for i in range(N-1, -1, -1):
    Y = W if i==0 else a[i-1]
    dp[i][0] = abs(a[N-1]-Y)
    
    for j in range(i+1, N):
        dp[i][0] = max(dp[i][0], dp[j][1])
    
    X = Z if i==0 else a[i-1]
    dp[i][1] = abs(a[N-1]-X)
    
    for j in range(i+1, N):
        dp[i][1] = min(dp[i][1], dp[j][0])

print(dp[0][0])

Submission status: Accepted

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

if N == 1:
  ans = abs(A[0]-W)
else:
  ans = max(abs(A[-1]-W),abs(A[-2]-A[-1]))
print(ans)

Submission status: Accepted

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

ans = abs(A[-1] - W)
if 2 <= N: ans = max(ans, abs(A[-2] - A[-1]))

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, Z, W = MAP()
A = [W] + LIST()

memo = list2d(N+1, 2, -1)
def rec(cur, prev, turn):
    if cur == N:
        return abs(A[cur] - A[prev])
    if memo[cur][turn] != -1:
        return memo[cur][turn]
    
    if turn == 0:
        res = 0
        for nxt in range(cur+1, N+1):
            res = max(res, rec(nxt, cur, 1 - turn))
    else:
        res = INF
        for nxt in range(cur+1, N+1):
            res = min(res, rec(nxt, cur, 1 - turn))
    memo[cur][turn] = res
    return res
print(rec(0, 0, 0))

Submission status: Accepted

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


if N == 1:
    print(abs(W-A[0]))
else:
    print(max(abs(W-A[-1]), abs(A[-1]-A[-2])))

Submission status: Accepted

Solution code:
import sys

n, z, w, *a = map(int, sys.stdin.read().split())

def main():
    if n == 1:
        return abs(a[n-1] - w)
    return max(abs(a[n-1] - w), abs(a[n-1] - a[n-2]))
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Z, W = MAP()
a = LIST()

if N == 1:
	print(abs(a[0]-W))
else:
	print(max(abs(a[-1]-W), abs(a[-2]-a[-1])))

Submission status: Accepted

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(abs(A[-1]-w), abs(A[-1]-A[-2])))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, Z, W = rl()
A = rl()
answer = abs(A[-1] - W)
if N >= 2:
    answer = max(answer, abs(A[-2]-A[-1]))
print(answer)
#04

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
dp = [[float("inf"), 0] for _ in range(N)]
dp[-1][0] = abs(a[-1] - W)
dp[-1][1] = 0
for i in range(N - 1):
  dp[-1][1] = max(dp[-1][1], abs(a[i] - a[-1]))
#print(dp)
for i in range(N - 2, -1, -1):
  for j in range(N - 1, i, -1):
    dp[i][0] = min(dp[i][0], dp[j][1], abs(a[i] - a[j]))
    dp[i][1] = max(dp[i][1], dp[j][0], abs(a[i] - a[j]))
#print(dp)
res = 0
for i in range(N): res = max(res, dp[i][0])
print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

if len(a) > 1:
    print(max(abs(a[-1]-y), abs(a[-1]-a[-2])))
else:
    print(abs(a[-1]-y))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, Z, W = list(map(int, input().split()))
A = [W] + list(map(int, input().split())) # A[0]=W, A[i]=ai

GX = [None]*N # GX[i] := YがA[i] を取った直後の状況から到達しうる最大のスコア
GY = [None]*N # GY[i] := XがA[i] を取った直後の状況から到達しうる最小のスコア
minGX = 10**20
maxGY = 0

for k in range(N-1, -1, -1):
    GX[k] = max(abs(A[k]-A[N]), maxGY)
    GY[k] = min(abs(A[k]-A[N]), minGX)
    minGX = min(minGX, GX[k])
    maxGY = max(maxGY, GY[k])

print(GX[0])

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
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()))

"""
山札がなくなると終了かつ必ず1枚は引かなくてはいけない
⇒最後の1枚は必ずどちらかの手になる(山札が1枚の場合、必ず自分の手になる)
先攻はそれを自分の手にするか、相手の手にするかを選べる
自分の手にする場合、1ターン目で全部の手札を取る
相手の手にする場合、1ターン目で最後から2番目まで全部取る
この2通りなのでこれの大きい方を選択
"""
n,z,w = LI()
a = LI()
if n == 1:
    ans = abs(a[0] - w)
else:
    ans = max(abs(a[-2]-a[-1]),abs(a[-1]-w))
print(ans)

Submission status: Accepted

Solution code:
N,Z,W=map(int,input().split())
A=[int(x) for x in input().split()]
if N==1:
  answer=abs(A[0]-W)
else:
  answer=max(abs(W-A[-1]),abs(A[-1]-A[-2]))
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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(abs(a[n-1]-w),abs(a[n-1]-a[n-2])))

Submission status: Accepted

Solution code:
n,z,w = map(int,input().split())
a = list(map(int,input().split()))
xp = [0]*(n)
yp = [10000000000]*(n)
xp[0] = abs(a[n-1]-w)
for i in reversed(range(n)):
    for j in range(i+1,n):
        xp[i] = max(xp[i], yp[j])
        yp[i] = min(yp[i], xp[j])
    xp[i] = max(xp[i], abs(a[i-1]-a[n-1]))
    yp[i] = min(yp[i], abs(a[i-1]-a[n-1]))
print(xp[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)

def solve(N: int, Z: int, W: int, a: "List[int]"):
    # memo[i][j] = 手番がi(X:0,Y:1)のときすでにj-index引いてる
    memo = [[0]*N for _ in range(2)]

    def maxValue(z:int, w:int, i: int, player:str) -> int:
        if i >= N:
            return abs(z-w)

        if player == "X": ## playerXが操作する。価値がmaxになるように
            if memo[0][i] > 0:
                return memo[0][i]

            value = 0
            for j in range(i,N):
                value = max(maxValue(a[j],w,j+1,"Y"),value)
            memo[0][i] = value
        else: ## yが操作,価値がminになるように
            if memo[1][i] > 0:
                return memo[1][i]
            value = 10**9
            for j in range(i,N):
                value = min(maxValue(z,a[j],j+1,"X"),value)
            memo[1][i] = value

        return value        

    print(maxValue(Z,W,0,"X"))
    return

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: Accepted

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

def solve(N: int, Z: int, W: int, a: "List[int]"):
    print(max(abs(a[N-1]-a[N-2]),abs(a[N-1]-W)))
    return


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: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
if N > 1:
    print(max(abs(W-a[-1]), abs(a[-1] - a[-2])))
else:
    print(abs(W - a[0]))