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:
import sys
sys.setrecursionlimit(10 ** 5)

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
a += [W] #最後にYさんの手札を加えておく
dp_T = [-1] * (N + 1) #Xの手番
dp_F = [-1] * (N + 1) #Yの手番

def calc(n, flag): #n: 残りの山の枚数　flag: ターンの管理
    #既に計算済みの場合その値を返す
    if flag == True and dp_T[n] != -1:
        return dp_T[n]
    if flag == False and dp_F[n] != -1:
        return dp_F[n]

    if n == 1: #山の残り枚数が1枚の時 -->引くしかなく得点が決定
        return abs(a[0] - a[n])
    if flag == True: #Xのターン-->大きくしたい
        tmp = 0
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n: #残り枚数0で相手に渡す = 自分が最後の1枚を引く -->相手の手札が決まっているから得点が決定
                tmp = max(tmp, abs(a[0]-a[n]))
            else: #残り枚数が1枚以上ある時、手番は相手に変える
                tmp = max(tmp, calc(n-i, not flag))
        dp_T[n] = tmp
        return tmp
    if flag == False: #Yのターン-->小さくしたい
        tmp = 10 ** 10 #最大値
        for i in range(1, n + 1): #自分が引く枚数 = 1 ~ n枚
            if i == n - 1: #残り0枚で相手に渡す
                tmp = min(tmp, abs(a[0] - a[n]))
            else:
                tmp = min(tmp, calc(n-i, not flag))
        dp_F[n] = tmp
        return tmp

print (calc(N, True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,z,w=map(int,input().split())
a_list=list(map(int,input().split()))
dp_m=[0]*n
for i in range(n-2,-1,-1):
    temp=10**10
    for j in range(i+1,n):
        if j==n-1:
            temp=min(temp,abs(a_list[i]-a_list[n-1]))
        else:
            temp2=max(abs(a_list[j]-a_list[n-1]),dp_m[j+1])
            temp=min(temp,temp2)
    dp_m[i]=max(dp_m[i+1],temp)
ans=max(dp_m[0],abs(a_list[n-1]-w))
print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Solution code:


def main():
    n, jibun, aite = map(int, input().split())
    data = list(map(int, input().split()))
    if n == 1:
        print(abs(aite - data[-1]))
    else:
        print(max(abs(aite - data[-1]), abs(data[-1] - data[-2])))



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [0] * (N + 1)
    for i in range(N):
        dp[i + 1] = max(abs(a[i] - W), abs(a[i - 1] - a[i]))
    print(dp[-1])


main()

Submission status: Accepted

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


main()

Submission status: Accepted

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

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

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 = list(map(int,input().split(" ")))
nums = list(map(int,input().split(" ")))
c1 = abs(nums[-1]-W)
c2 = -100
if len(nums) > 1:
    c2 = abs(nums[-1]-nums[-2])
print(max(c1,c2))

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()))
INF=10**19
dp=[[0]*2 for i in range(N+1)]
for i in range(N-1,-1,-1):
    dp[i][0]=-INF
    if i: Y=a[i-1]
    else: Y=W
    dp[i][0]=max(dp[i][0],abs(Y-a[N-1]))
    for j in range(i+1,N): dp[i][0]=max(dp[i][0],dp[j][1])

    dp[i][1]=INF
    if i: X=a[i-1]
    else: X=Z
    dp[i][1]=min(dp[i][1],abs(X-a[N-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())
INL = list(map(int,input().split()))

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
# fin = open('in_4.txt', 'r')
# sys.stdin = fin
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

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

    # write code
    # †私は証明のない決め打ちを提出しました†
    if N == 1:
        print(abs(a[-1]-W))
    elif abs(a[-1] - W) > abs(a[-1] - a[-2]):
        print(abs(a[-1] - W))
    else:
        print(abs(a[-1] - a[-2]))

Submission status: Accepted

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, _, W = MI()
    A = LI()

    if N == 1:
        print(abs(W-A[-1]))
    else:
        #初手で前取りか寸止め侍かするのと同じ(２手目で同じことがされてしまうから)
        print(max(abs(W-A[-1]), abs(A[-1]-A[-2]) ))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, Z: int, W: int, a: "List[int]"):
    if N == 1:
        print(abs(a[0]-W))
    else:
        print(max(abs(a[-1]-a[-2]), abs(a[-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=1の時、山札とＹの初期手札が答え
n>=2の時、
・Ｘは得点の最大化を狙う
・Ｙは得点の最小化を狙う＝Ｘの邪魔をする
山札内の得点の最大化をできるカードをＸが選んでも、Ｙはそれを邪魔する動きをとるので、真に最大化すること(Xの狙いを達成すること)はできない
→選べるのはＹの初期値＆山札最後（Ｘがすべて取る）か、最後とその一つ手前の比較（Ｘが一枚残してすべて取る）のどちらかにするのがましな選択



"""


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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,z,w = f()
    a = f()

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

solve()

Submission status: Accepted

Solution code:
# だいぶ誤読

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

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

print(answer)

Submission status: Accepted

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

score = []

# only X
score.append(abs(a[-1] - w))

if n > 1:
    # X -> Y
    score.append(abs(a[-2] - a[-1]))

print(max(score))

Submission status: Accepted

Solution code:
import sys

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

N, Z, W = list(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:
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(1, N)):
    y = A[i - 1] if i > 0 else W
    dpx[i] = max(abs(A[-1] - A[i - 1]), dpy[i + 1])
    dpx[i] = min(dpx[i], dpx[i + 1])

    dpy[i] = min(abs(A[-1] - A[i - 1]), dpx[i + 1])
    dpy[i] = max(dpy[i], dpy[i + 1])

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

Submission status: Accepted

Solution code:
n,z,w=map(int,input().split())
a=[int(i) for i in input().split()]
if n>=2:
    print(max(abs(a[-1]-w),abs(a[-1]-a[-2]) ))
else:
    print(abs(a[-1]-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))
else:
    print(max(abs(w-a[-1]),abs(a[-1]-a[-2])))

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

Submission status: Accepted

Solution code:
import itertools
from collections import Counter
from collections import defaultdict
import bisect

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


if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

print(mx)

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

Submission status: Accepted

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

X = [0]*(N+1)
Y = [1e9]*(N+1)

for i in range(N,0,-1):
  X[i] = max([abs(A[i-1] - A[N])] + [Y[j] for j in range(i+1,N+1)])
  Y[i] = min([abs(A[i-1] - A[N])] + [X[j] for j in range(i+1,N+1)])

print(X[1])

Submission status: Accepted

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

if N > 1:
    print(max(abs(A[-1] - Y), abs(A[-1] - A[-2])))
else:
    print(abs(A[-1] - Y))

Submission status: Accepted

Solution code:
n, z, w = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

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

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

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
z = [int(_) for _ in input().split()]
if a == 1:
  sco = abs(z[0]-c)
else:
  if abs(z[-1] - c) > abs(z[-2] - z[-1]):
    sco = abs(z[-1] - c)
  else:
    sco = abs(z[-2] - z[-1])
    
print(sco)

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

Submission status: Accepted

Solution code:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
if n > 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 = map(int, input().split())
if N == 1:
    a = int(input())
    print(abs(a - W))
else:
    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 =list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
n,x,y = map(int,input().split())

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

#fin = open("rand_11.in","r")

#n,x,y = map(int,fin.readline().split())

#A = list(map(int,fin.readline().split()))

#fin.close()

X = [0]*n
Y = [0]*n
dpX = list(range(n)) 
dpY = list(range(n)) 

for i in range(n):
    X_bound = 10**18+1
    Y_bound = -10**18-1
    for j in range(i+1,n):
        X_bound = min(X_bound,abs(A[j]-A[i]))
        Y_bound = max(Y_bound,abs(A[j]-A[i]))
    X[i] = X_bound
    Y[i] = Y_bound

X[n-1] = -10**18-1
Y[n-1] = 10**18+1

for i in range(n-2,-1,-1):
    if X[dpX[i+1]]>X[i]:
        dpX[i] = dpX[i+1]
    if Y[dpY[i+1]]<Y[i]:
        dpY[i] = dpY[i+1]
#print(max(X))
#print(X)
#print(Y)
#print(dpX)
#print(dpY) 

curr = 0
hisatsuX = []
hisatsuY = []
while curr<n:
    hisatsuX.append(abs(A[-1]-y))
    if X[dpX[curr]]<abs(A[-1]-y):
        curr = n
        x = A[-1]
    else:
        x = A[dpX[curr]]
        curr = dpX[curr]+1
    #print(x)
    hisatsuY.append(abs(A[-1]-x))
    if curr >= n:
        break
    if Y[dpY[curr]]>abs(A[-1]-x):
        curr = n
        y = A[-1]
    else:
        y = A[dpY[curr]]
        curr = dpY[curr]+1
    #print(y)
for i in range(len(hisatsuX)):
    if hisatsuX[i] >= abs(x-y):
        print(hisatsuX[i])
        exit(0)
    if hisatsuY[i] <= abs(x-y):
        print(hisatsuY[i])
        exit(0)
print(abs(x-y))

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

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))  # 入力をリストにして受け付け
b = list(map(int, input().split()))

try:
    print(max(abs(a[2] - b[-1]), abs(b[-1] - b[-2]))) # xさんが最後から二番目の数か最後の数どちらを取ればよいかを判断
except:  # 与えられる数が一つの場合
    print(abs(a[2] - b[0]))

Submission status: Accepted

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

#初手で全部引く
ans1 = a[-1]-w
#初手で一枚残して引く
if len(a) > 1:
  ans2 = a[-2]-a[-1]
else:
  ans2 = 0

print(max(abs(ans1),abs(ans2)))

Submission status: Accepted

Solution code:
from sys import exit
N,Z,W = [int(n) for n in input().split()]
a = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# L = len(S)
# T = str(input())
if N == 1:
    print(abs(W-a[N-1]))
else:
    print(max(abs(a[N-1]-a[N-2]), abs(W-a[N-1])))

Submission status: Accepted

Solution code:
def _abs(N: int, Z: int, W: int, A: list) -> int:
    if N == 1:
        return abs(A[0] - W)
    return max(abs(A[N-1] - A[N-2]), abs(A[N-1] - W))


if __name__ == "__main__":
    N, Z, W = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = _abs(N, Z, W, A)
    print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    n, z, w = map(int, input().split())
    A = list(map(int, input().split()))

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


    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = LS()
    t = sorted(s)
    if s[0] == s[1]:
        print("=")
    elif s[0] == t[0]:
        print("<")
    else:
        print(">")

#B
def B():
    x,y,z = LI()
    k = 0
    for i in range(1000000000):
        k += y+z
        if k+z>x:
            print(i)
            quit()

#C
def C():
    n,m = LI()
    print((100*n+1800*m)*2**m)
#D
def D():
    n,z,w = LI()
    a = LI()
    if len(a) == 1:
        print(abs(a[0]-w))
    else:
        print(max(abs(a[-1]-w),abs(a[-2]-a[-1])))
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
if len(a) == 0:
    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())
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:
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[N-1]-W),abs(L[N-2]-L[N-1])))

Submission status: Accepted

Solution code:
n, _, w = map(int, input().split())
a = list(map(int, input().split()))
a = [w] + a
dp = [[0 for _ in range(2)] for _ in range(n+1)]
for i in range(n, 0, -1):
    dp[i][0] = abs(a[n] - a[i-1])
    dp[i][1] = abs(a[n] - a[i-1])
    for j in range(1, n-i+1):
        dp[i][0] = max(dp[i][0], dp[i+j][1])
        dp[i][1] = min(dp[i][1], dp[i+j][0])
print(dp[1][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[n-1]-w),abs(a[n-1]-a[n-2])))

Submission status: Accepted

Solution code:
#078-C 
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,z,w=IL()
a=IL()
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:
    ko = abs(w-a[-1])
    ki = abs(a[-2]-a[-1])

    print(max(ko,ki))
else:
    print(abs(a[0]-w))

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Z, W] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    A = []
    input_raw = read_func().strip().split()
    for i in range(N):
        A.append(int(input_raw[i]))

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

if __name__ == '__main__':
    main()

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

Submission status: Accepted

Solution code:

a,b,c=map(int,input().split())
x = list(map(int,input().split()))
if a == 1:
    print(abs(c-x[-1]))
else:
    print(max(abs(c-x[-1]),abs(x[-1]-x[-2])))

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

Submission status: Accepted

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

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

print(ans)

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,w = map(int,input().split())
a = list(map(int,input().split()))
if n == 1:
    print(abs(a[0] - w))
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 = 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:
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc085/editorial.pdf
・公式解、O(1)の一発解法
・思いつけばいいけど、そういつも上手くいかないよね…。
"""
 
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))

if N == 1:
    print(abs(aN[0] - W))
else:
    # Xが最後まで引くか、最後から2番目まで引くか
    print(max(abs(aN[-1] - W), abs(aN[-2] - aN[-1])))

Submission status: Accepted

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

"""
参考：https://kimiyuki.net/writeup/algo/atcoder/arc-085-d/
　　　https://atcoder.jp/contests/abc078/submissions/3854338
・ミニマックス法
・メモ化再帰
・メモの持ち方をシンプルにした版
"""

import sys
from collections import defaultdict

# 再帰呼び出しの回数制限(デフォルト1000)
sys.setrecursionlimit(10 ** 9)
 
N, Z, W = map(int, input().split())
aN = list(map(int, input().split()))

# メモ[手番][残り山札数] = このルートでのmax,min
memo = [[0] * (N+1) for _ in range(2)]

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    # 先手番
    if turn % 2 == 0:
        # 既に見た局面ならメモの内容を返す
        if memo[0][rest]: 
            return memo[0][rest]
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            mx = max(dfs(turn+1, N-idx, x, y), mx)
        # ここより深い所を探し終わったので結果をメモする
        memo[0][rest] = mx
        return mx
    # 後手番
    else:
        if memo[1][rest]: 
            return memo[1][rest]
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            mn = min(dfs(turn+1, N-idx, x, y), mn)
        memo[1][rest] = mn
        return mn

print(dfs(0, N, Z, W))

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

Submission status: Accepted

Solution code:
N, X, Y = map(int, input().split())
A = list(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, *A = map(int, open(0).read().split())
ans = abs(A[-1] - W)
if N >= 2:
    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()
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 = input().split()
a = [int(m) for m in a]
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:
    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 = list(map(int,input().split()))
a = list(map(int,input().split()))
if len(a)>1:
    ans = max(abs(a[-1]-a[-2]), abs(W-a[-1]))
else:
    ans = abs(W-a[-1])
print(ans)