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:
N, Z, W = map(int, input().split(' '))
a= list(map(int, input().split(' ')))
if N == 1:
    print(abs(a[-1]-W))
elif abs(Z-W) < min(abs(a[-1]-W), abs(a[-2]-a[-1])):
    print(max(abs(a[-1]-W), abs(a[-2]-a[-1])))
else:
    print(max(abs(a[-2]-a[-1]), abs(a[-1]-W)))

Submission status: Accepted

Solution code:
n,z,w=map(int,input().split())
a=[int(_) for _ in input().split()]
a.reverse()
dp=[[0,0] for i in range(n)]
# dp[i][j] i番目までのカードを使用しjから始めた場合のゲームのスコア
for i in range(n):
    if i==n-1:
        score1=abs(w-a[0])
        score2=abs(z-a[0])
        dp[i][0]=score1
        dp[i][1]=score2
    else:
        score=abs(a[i+1]-a[0])
        dp[i][0]=score
        dp[i][1]=score
    for j in range(i):
        dp[i][0]=max(dp[i][0],dp[j][1])
        dp[i][1]=min(dp[i][1],dp[j][0])
print(dp[n-1][0])

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,Z,W = II()
a = III()

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split()) # 必ず捨てられるため、zの値は関係ない
    A=[w]+list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] # dp[i][turn] 消費枚数i,turnの手から始まるときの最適解

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        # i+1からn-1のdp[1-turn]を埋めておく(i=n-1のときterminate)
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            res=max(res,abs(A[-1]-A[i]))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            res=min(res,abs(A[-1]-A[i]))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] # dp[i][turn] 消費枚数i,turnの手から始まるときの最適解

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        # i+1からn-1のdp[1-turn]を埋めておく(i=n-1のときterminate)
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1]
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] # dp[i][turn] 消費枚数i,turnの手から始まるときの最適解

    def dfs(i,turn):
        if(dp[i][turn] is not None): return

        # i+1からn-1のdp[1-turn]を埋めておく(i=n-1のときterminate)
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1] if(i!=0) else z # x=zとなることは無い
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] # dp[i][turn] 消費枚数i,turnの手から始まるときの最適解

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        # i+1からn-1のdp[1-turn]を埋めておく(i=n-1のときterminate)
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1] if(i!=0) else z # x=zとなることは無い
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    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])))
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)
 
N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
 
memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:    #カードの残り枚数と、どちらの手番かが決まっていたら最終スコアはいつも同じ
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret
 
 
print func(N,Y,0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:    #カードの残り枚数と、どちらの手番かで最終スコアはいつも同じ
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:    #カードが残りn枚で、どちらの番かが決まっていたら最終スコアはいつも同じ
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Submission status: Accepted

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

N, Z, W, *a = map(int, 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:
def examD():
    N, Z, W = LI()
    A = LI()
    if N>=2:
        ans = max(abs(A[-2]-A[-1]),abs(A[-1]-W))
    else:
        ans = abs(A[0]-W)
    print(ans)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,Z,W = inpl()
aa = inpl()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
ans = abs(W-a[-1])
for i in range(N-1):
    hoge = abs(a[i]-a[-1])
    for j in range(i+1,N-1):
        hoge = min(hoge,abs(a[-1]-a[j]))
    ans = max(ans,hoge)
print(ans)

Submission status: Accepted

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

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

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

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[-2] - a[-1])))

Submission status: Accepted

Solution code:
#  解説見た

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

if n == 1:
    print(abs(a[-1] - y))
else:
    print(max(abs(a[-1] - y), 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
n, z, w = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
if n > 1 and abs(a_ls[-1] - w) < abs(a_ls[-2] - a_ls[-1]):
    x = a_ls[-2]
    y = a_ls[-1]
else:
    x = a_ls[-1]
    y = w
print(abs(x - y))

Submission status: Accepted

Solution code:
n, z, w = map(int, input().split())
list_a = list(map(int, input().split()))
if n == 1:
  print(abs(list_a[0] - w))
else:
  # 手番渡してカウンター喰らうなら、手番渡す価値がない
  result_all = abs(list_a[-1] - w)
  result_before = abs(list_a[-2] - list_a[-1])
  print(max(result_all, result_before))

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, Z, W = inpl()
a = inpl()[::-1]
a.append(W)
# i = 1
X = Y = Xmin = Ymax = abs(a[0]-a[1])
for i in range(2,N+1):
    X = max(Ymax,abs(a[i]-a[0]))
    Y = min(Xmin,abs(a[i]-a[0]))
    Ymax = max(Ymax, Y)
    Xmin = min(Xmin, X)
print(X)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, Z, W = inpl()
a = inpl()[::-1]
a.append(W)
X = [0]*(N+1)
Y = [10**9]*(N+1)
if N == 1:
    print(abs(W-a[0]))
    exit()
# i = 1
Xmin = Ymax = abs(a[0]-a[1])
for i in range(2,N+1):
    X = max(Ymax,abs(a[i]-a[0]))
    Y = min(Xmin,abs(a[i]-a[0]))
    Ymax = max(Ymax, Y)
    Xmin = min(Xmin, X)
print(X)

Submission status: Accepted

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

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(a[0]-W))
else:
  print(max(abs(a[-1]-W), abs(a[-1]-a[-2])))

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, _, y = map(int, input().split())
a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
# ABC078 D - ABS
N,Z,W = map(int, input().split())
A = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

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

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    INF = 10**12

    ans = 0
    for i in range(N-1):
        s = INF
        for j in range(i+1, N):
            if j < N-1:
                s = min(s, abs(A[j]-A[N-1]))
            else:
                s = min(s, abs(A[j]-A[i]))
        ans = max(s, ans)

    ans = max(ans, abs(A[N-1]-W))

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

# どちらかが必ず山札の底のカードで勝負する
# Yに行動の選択肢を与えるとスコアを小さくされてしまうので、XはYに選択肢を与えないように行動する
# Xは山札の底のカードを自分で取るかYに取らせるかを選択する
# Xが自分で山札の底のカードを取る場合、初手で全取りしなければYに選択肢を与えてしまう
# Xが自分で山札の底のカードを取らない場合、底のカードだけ残してYに取らせなければYに選択肢を与えてしまう

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

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 = float('inf')
MOD = 10 ** 9 + 7

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

# memo[i][j] := 現在iターンで、山札からj枚目まで取った状態
memo = list2d(2, N+1, None)
def rec(turn, cnt):
    if memo[turn][cnt] is not None:
        return memo[turn][cnt]
    # 先手番
    if turn % 2 == 0:
        res = -INF
        for nxt in range(cnt+1, N):
            res = max(res, rec(1-turn, nxt))
        # 最後まで取る時は、結果を取得
        res = max(res, abs(A[N]-A[cnt]))
    # 後手番
    else:
        res = INF
        for nxt in range(cnt+1, N):
            res = min(res, rec(1-turn, nxt))
        res = min(res, abs(A[cnt]-A[N]))
    memo[turn][cnt] = res
    return res

ans = rec(0, 0)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,x,y=[int(j) for j in input().split()]
a=[int(j) for j in input().split()]
a=[y]+a
print(max(abs(y-a[-1]),abs(a[-2]-a[-1])))

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 >= 2:
    ans = max(ans, 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()))
dp1 = [0]*N
dp2 = [0]*N
dp1[N-2] = dp2[N-2] = abs(a[N-2]-a[-1])
for i in range(N-2)[::-1]:
    dp1[i] = max(abs(a[i]-a[-1]), max(dp2[j] for j in range(i+1, N-1)))
    dp2[i] = min(abs(a[i]-a[-1]), min(dp1[j] for j in range(i+1, N-1)))
if N==1:
    ans = abs(W-a[-1])
else:
    ans = max(abs(W-a[-1]), max(dp2[i] for i in range(N-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))
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()))

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

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

Submission status: Accepted

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

memoX = {}
memoY = {}
memo = 0

def X(n,z,w):
    score = 0
    if n == 0:
        if not (0,z,w) in memoX:
            memoX[(0,z,w)] = abs(z-w)
        return abs(z-w)
    else:
        if (n,w) in memoX:
            global memo
            memo += 1
            return memoX[(n,w)]
        else:
            for i in range(n):
                tmp = Y(i,A[N-1-i],w)
                if score < tmp:
                    score = tmp
            memoX[(n,w)] = score
            return score

def Y(n,z,w):
    score = float("inf")
    if n == 0:
        if not (0,z,w) in memoY:
            memoY[(0,z,w)] = abs(z-w)
        return abs(z-w)
    else:
        if (n,z) in memoY:
            global memo
            memo += 1
            return memoY[(n,z)]
        else:
            for i in range(n):
                tmp = X(i,z,A[N-1-i])
                if score > tmp:
                    score = tmp
            memoY[(n,z)] = score
            return score
    
ans = X(N,Z,W)
#print(memo)
#print(len(memoX))

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

dp = [[0]*2 for i in range(n)]
for i in range(n-1, -1, -1):
    # 先手番
    # 後手が持っているカード
    x = a[i-1] if i else w
    # 残りを全部取る時
    dp[i][0] = abs(a[-1] - x)
    # 1枚以上残す時
    for j in range(i+1, n):
        dp[i][0] = max(dp[i][0], dp[j][1])

    # 後手番
    # 先手が持っているカード
    x = a[i-1] if i else z
    dp[i][1] = abs(a[-1]-x)
    # 1枚以上残す時
    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()))
ans = abs(a[-1]-w)
if n > 1:
    ans = max(ans, abs(a[-1]-a[-2]))
print(ans)

Submission status: Accepted

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()
if n == 1:
    print(abs(a[-1] - w))
else:
    print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))

Submission status: Accepted

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
    #最小化する方向に動く
    tmp = abs(a[n-2]-a[n-1])
    tmp2 = abs(a[n-1]-w)
    ans = max(tmp,tmp2)
  print(ans)
solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,z,w =m()
a = l()
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()))

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

Submission status: Accepted

Solution code:
N, Z, W = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
#Xさんが最初に全部引くか、Xさんが最後から2枚目まで引く
print(max(abs(W - A[-1]), abs(A[N - 2] - A[-1])))

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main_old(): 
    N, _, W = LI()
    a = LI()

    # 初手でラストまで取るとき
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return
    res2 = abs(a[-1] - a[-2])

    # 最後から n 枚目を取るときの max, min
    max_li = [0, res, res2] + [0 for _ in range(N)]
    min_li = [INF, res, res2] + [INF for _ in range(N)]
    for i in range(3, N+1):
        take_all = abs(a[-i] - a[-1])
        max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
        min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])

    print(max(max_li))

def main():
    N, _, W = LI()
    a = LI()

    # 初手でラストまで取るとき
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return

    # 初手でラスト1つ手前まで取るとき
    res2 = abs(a[-1] - a[-2])

    # res2 以上の結果を、カードをより少なく取ることで得ることはできない。
    # なぜなら、たとえそのような選び方を見つけたような気がしても、Y にラスト1つ手前まで取られてしまったら結局結果は res2 になってしまうため。
    # これ以上の結果を得ることはできないのでこれで満足するしかない。

    print(max(res, res2))

main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, _, W = LI()
    a = LI()

    # 初手でラストまで取るとき
    res = abs(a[-1] - W)
    if N == 1:
        print(res)
        return
    res2 = abs(a[-1] - a[-2])

    # 最後から n 枚目を取るときの max, min
    max_li = [0, res, res2] + [0 for _ in range(N)]
    min_li = [INF, res, res2] + [INF for _ in range(N)]
    for i in range(3, N+1):
        take_all = abs(a[-i] - a[-1])
        max_li[i] = min([min_li[j] for j in range(2, i)]+[take_all])
        min_li[i] = max([max_li[j] for j in range(2, i)]+[take_all])

    print(max(max_li))


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())
A=list(map(int,input().split()))
print(abs(A[0]-W) if N==1 else max(abs(A[-1]-W),abs(A[-1]-A[-2])))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n,x = [int(i) for i in readline().split()]
#n = int(input())
n,z,w = [int(i) for i in readline().split()]
a = [w] + [int(i) for i in readline().split()]
n += 1

dps = [0]*(n)+[10**18]
dpg = [0]*(n+1)

for i in range(n-1,0,-1):
    dps[i] = max(max(dpg[j] for j in range(i+1,n+1)),abs(a[-1]-a[i-1]))
    dpg[i] = min(min(dps[j] for j in range(i+1,n+1)),abs(a[-1]-a[i-1]))
    

print(dps[1])
#print(dps)
#print(dpg)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,z,*l=map(int,open(0).read().split());print(max(abs(l[n]-l[n-1]),abs(l[n]-l[0])))

Submission status: Accepted

Solution code:
n,z,w,*l=map(int,open(0).read().split())
if len(l)<2:l+=[l[0]]
print(max(abs(l[-1]-l[-2]),abs(w-l[-1])))

Submission status: Accepted

Solution code:
N,Z,W = (int(x) for x in input().split())
A_arr = [int(x) for x in input().split()]

if N == 1:
    print(abs(A_arr[0]-W))
else:
    print(max(abs(A_arr[-1]-W), abs(A_arr[-2]-A_arr[-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-2]-a[n-1]),abs(a[n-1]-w)))

Submission status: Accepted

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()
    
    if N ==1:
        print(abs(A[-1]-W))
    else:
        print(max(abs(A[-1]-W), abs(A[-2]-A[-1])))
    
    '''
    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: Accepted

Solution code:
*a,b=map(int,open(0).read().split());print(max(abs(a[-1]-b),abs(a[2]-b)))

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-1] - a[N - 2])))