Problem:


Score : 500 points

Problem Statement

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

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

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

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

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

Constraints

All input values are integers.

1 \leq N \leq 2000

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

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

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

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

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

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999



Sample input:
3 100 100
10 1000 100


Sample output:
900

Submission status: Wrong Answer

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

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

# kado z
if n > 1:
    z = a[-1]
    w1 = max(a[1:-1])
    w2 = min(a[1:-1])
    w3 = w

    ans1 = max(abs(z-w1), abs(z-w2), abs(z-w3))
else:
    ans1 = abs(a[-1]-w)

# kado w
if n > 1:
    w = a[-1]
    z1 = max(a[0:-1])
    z2 = min(a[0:-1])
    ans2 = max(abs(z1-w), abs(z2-w))
else:
    w = a[-1]
    ans2 = abs(abs(z-w))

# print(ans1, ans2)
print(max(ans1, ans2))

Submission status: Wrong Answer

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

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

# kado z
if n > 1:
    z = a[-1]
    w1 = max(a[1:-1])
    w2 = min(a[1:-1])
    w3 = w

    ans1 = max(abs(z-w1), abs(z-w2), abs(z-w3))
else:
    ans1 = abs(a[-1]-w)

# kado w
if n > 1:
    w = a[-1]
    z1 = max(a[0:-1])
    z2 = min(a[0:-1])
    ans2 = max(abs(z1-w), abs(z2-w))
else:
    ans2 = abs(abs(z-w))

# print(ans1, ans2)
print(max(ans1, ans2))

Submission status: Wrong Answer

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

def maximize(st):
  score = abs(A[st] - W)
  ret = st
  for i in range(st+1, N):
    cand = abs(A[i] - W)
    if score <= cand:
      score = cand
      ret = i
  return ret

def minimize(st):
  score = abs(Z - A[st])
  ret = st
  for i in range(st+1, N):
    cand = abs(Z - A[i])
    if score >= cand:
      score = cand
      ret = i
  return ret

i = 0
while i < N:
  end = maximize(i)
  Z = A[end]
  i = end + 1
  if i == N:
    break
  end = minimize(i)
  W = A[end]
  i = end + 1

print(abs(Z-W))

Submission status: Wrong Answer

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

def maximize(st):
  score = abs(Z - W)
  ret = st
  for i in range(st+1, N):
    cand = abs(A[i] - W)
    if score <= cand:
      score = cand
      ret = i
  return ret

def minimize(st):
  score = abs(Z - W)
  ret = st
  for i in range(st+1, N):
    cand = abs(Z - A[i])
    if score >= cand:
      score = cand
      ret = i
  return ret

i = 0
while i < N:
  end = maximize(i)
  Z = A[end]
  i = end + 1
  if i == N:
    break
  end = minimize(i)
  W = A[end]
  i = end + 1

print(abs(Z-W))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, Z, W = map(int, input().split())
    a = list(map(int, input().split()))
    # print(a)
    ans = - INF
    for i in range(N):# Xさんの手札
        tmp = INF
        for j in range(i+1,N):# Yさんの手札
            # print(i,j)
            # print(a[i],a[j])
            tmp = min(tmp, abs(a[i]-a[j]))
        if i == N-1:
            tmp = abs(a[N-1] - W)
        ans = max(ans, tmp)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,z,w = map(int, raw_input().split() ) #3 100 1000
ais = map(int, raw_input().split()) #10 100 100
m = abs(z - w)
for u,v in zip(ais, ais[1:]):
	m = max(m, (u - v))
m = max(m, abs(ais[-1] - w))
print m

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, Z, W = getNM()
A = getList()

# 後に来るもので絶対値最小のもの
rec_min = [0] * N
# rec_max = [0] * N
for i in range(N):
    if i == N - 1:
        rec_min[i] = W
        # rec_max[i] = W
        continue
    mi = i + 1
    # ma = i + 1
    for j in range(i + 1, N):
        if abs(A[j] - A[i]) <= abs(A[mi] - A[i]):
            mi = j
        # if abs(A[j] - A[i]) >= abs(A[ma] - A[i]):
            # ma = j
    rec_min[i] = A[mi]
    # rec_max[i] = A[ma]

ans = 0
for i in range(N):
    opt = abs(rec_min[i] - A[i])
    ans = max(ans, opt)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
def main():
    n,z,w=map(int, input().split())
    a=[int(i) for i in input().split()]
    #途中選り好みしても結局a_n - a_n-1になる
    if(n==1):
        print((abs(z-a[0])))
    else:
        print(max(abs(a[n-1]-a[n-2]), abs(a[n-1]-w)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
def main():
    n,z,w=map(int, input().split())
    a=[int(i) for i in input().split()]
    #途中選り好みしても結局a_n - a_n-1になる
    if(n==1):
        print(max(abs(z-a[0]),abs(a[0]-w)))
    else:
        print(max(abs(a[n-1]-a[n-2]), abs(a[n-1]-w)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
l=[]
k=[]
tmp=0
for i in range(n):
    if tmp<a[i]:
        tmp=a[i]
    l.append(tmp)
for i in range(n-1):
    ans=float("inf")
    for j in range(i+1,n):        
        m=a[i]
        mm=a[j]
        tmp=abs(m-mm)
        if tmp<ans:
            ans=tmp
    k.append(ans)
tmp=abs(a[n-1]-w)
k.append(tmp)
print(max(k))

Submission status: Wrong Answer

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

if n == 1:
    print(abs(A[0]-w))
else:
    # xが最後のカードを引く
    z1 = A[-1]
    w1 = min(A[:-1])
    # yが最後のカードを引く
    z2 = max(A[:-1])
    w2 = A[-1]
    print(max(abs(z1-w), abs(z1-w1), abs(z2-w2)))

Submission status: Wrong Answer

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

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

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

al1 = al[-2]
al2 = al[-1]

d1 = abs(al1-al2)
d2 = abs(al2-w)

print(max(d1,d2))

Submission status: Wrong Answer

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

dp = [[0, 0] for i in range(N)]
dp[-1][0] = abs(A[-1]- W)
dp[-1][1] = - 1
dp[-2][0] = dp[-2][1] = dp0max = dp1min = abs(A[-2] - A[-1])

for i in range(N-3, -1, -1):
  ai = A[i]
  diff = abs(ai - A[-1])
  dp[i][0] = min(diff, dp1min)
  dp[i][1] = max(diff, dp0max)
  dp0max = max(dp0max, dp[i][0])
  dp1min = min(dp1min, dp[i][1])

print(dp0max)

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

ans = abs(A[-1] - W)

for i in range(N - 1):
    ans = max(ans, abs(A[i] - A[-1]))

print(ans)

Submission status: Wrong Answer

Solution code:
n,z,w= map(int,input().split())
a=list(map(int,input().split()))
m=min(a[1:]) if n>1 else 10**9
m=min(m,w)

u=max(z,max(a))

print(u-m)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    m = abs(A[-1] - W)
    for i in range(N - 1):
        a = A[i]
        m = max(m, min(abs(a - t) for t in A[i + 1:]))
    return m

print(main())

Submission status: Wrong Answer

Solution code:
def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    m = abs(A[-1] - W)
    A.append(W)
    for i in range(N):
        a = A[i]
        m = max(m, min(abs(a - t) for t in A[i + 1:]))
    return m

print(main())

Submission status: Wrong Answer

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-2)):
        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: Wrong Answer

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-2)):
        for j in range(i-1):
            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: Wrong Answer

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

if n >= 2:
    x = abs(a[-1] - a[-2])
    y = abs(a[-1] - a[-2])

    dp_x = [abs(a[-1] - a[-2])]
    dp_y = [abs(a[-1] - a[-2])]

    for i in reversed(range(n-2)):
        # x が ai を手札としたときの最終スコア
        x, y = min(y, abs(a[i] - a[-1])), max(x, abs(a[i] - a[-1]))
        dp_x.append(x)
        dp_y.append(y)

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

# print(dp_x)
# print(dp_y)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

def func(i, j, xxyy):
    xy = deepcopy(xxyy)
    if i >= n:
        return abs(xy[0] - xy[1])
    if j == 0:
        tmp = 0
        for k in range(i, n):
            if tmp < abs(xy[1] - a[k]):
                xy[0] = a[k]
    if j == 1:
        tmp = inf
        for k in range(i, n):
            if tmp > abs(xy[0] - a[k]):
                xy[1] = a[k]
    res = []
    for k in range(i, n):
        if a[k] == xy[j]:
            debug(k)
            res.append(func(k + 1, int(not bool(j)), xy))
    debug(i, j, res)
    if j == 0:
        return max(res)
    else:
        return min(res)

n, z, w = MAP()
a = LIST()
xy = [z, w]
ans = func(0, 0, xy)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
ans=[]
ans.append(abs(max(a)-w))
x=max(a)
for i in range(n-1):
  ans.append(abs(x-a[-1]))
y=min(a)
for i in range(1,n):
  ans.append(abs(y-a[-1]))
print(max(ans))

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
ans=[]
ans.append(abs(max(a)-w))
x=max(a)
for i in range(n):
  if x==a[i] and i!=n-1:
    ans.append(abs(x-a[-1]))
    break
y=min(a)
if a[0]!=y:
  ans.append(abs(a[-1]-y))
print(max(ans))

Submission status: Wrong Answer

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


def calc(yv, idx):
    if idx in memo:
        return memo[idx]
    max_value = abs(yv - A[-1])
    max_value = max(max_value, min([abs(A[i]-A[-1]) for i in range(idx, n)]))

    for i in range(idx+1, n-1):
        max_value = max(max_value, calc(A[i], i+1))

    memo[idx] = max_value
    return memo[idx]


memo = {}
print(calc(w, 0))

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    num = a[i]##ここまでとる
    tmp = []
    for j in a[i+1:]:
        tmp.append(abs(num-j))
    m = max(tmp)
    if m == min(tmp):
        ans = max(ans,m)

print(ans)

Submission status: Wrong Answer

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

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

l_min,l_max=[],[]
for i in range(n-1):
    t=min(a[i+1:])
    l_min.append(t)
l_min.append(a[-1])
for i in range(n-1):
    t=max(a[i+1:])
    l_max.append(t)   
l_max.append(a[-1])

ans1=0
ans2=0
ans3=0
for i in range(1,n):
    t1=max(abs(a[i]-l_min[i]),abs(a[i]-l_max[i]))
    ans1=max(t1,ans1)
    t2=max(abs(z-l_min[i]),abs(w-l_max[i]))
    ans2=max(t2,ans2)
    t3=max(abs(w-l_max[i]),abs(w-l_min[i]))
    ans3=max(t3,ans3)

print(max(ans1,ans2,ans3))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for k in range(N):
    ans = max(ans,abs(a[k]-a[-1]))

print(ans)

Submission status: Wrong Answer

Solution code:
class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = (A[i], i)
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)
    

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

st = SegmentTree(A, max, (0, 0))
cur = 0
x = Z
y = W
while cur < N:
    x, cur = st.get(cur, N)
    cur += 1
    if cur < N:
        y, cur = st.get(cur, N)
        cur += 1

print(abs(x - y))

Submission status: Wrong Answer

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( max( abs(z-last),abs(w-last)))
    exit()

last2 = a[-2]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

turn = True
flag = False
p= max(a)
for i in range(n-1):
  if turn:
    if a[i] <= a[i+1]:
      continue
    elif a[i] < z and a[i] != p:
      continue
    else:
      z = a[i]
      turn = False
      if a[i] < z and a[i] == p:
        q = min(a[i+1:])
  else:
    if a[i] >= a[i+1]:
      continue
    elif a[i] > z and a[i] != q:
      continue
    else:
      z = a[i]
      turn = True
      if a[i] > z and a[i] == q:
        p = max(a[i+1:])
if turn:
  z = a[-1]
else:
  w = a[-1]
print(abs(z-w))

Submission status: Wrong Answer

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

p = max(a)
q = min(a)
if z < p:
  z = p
if w > q:
  w = q
print(abs(z-w))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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] = max(dp[i][1], dp[j][0])

print(dp[0][0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

last = a[-1]
flag = False
ans = 0

if len(a) > 1:
    while len(a) > 0:
        maxa = max(a)
        mina = min(a)
        if abs(last-y) < abs(maxa-y) and abs(last-y) < abs(mina-y):
            if abs(maxa-y) < abs(mina-y):
                while a[0] != mina:
                    a = a[1:]
                x = mina
                a = a[1:]
            else:
                while a[0] != maxa:
                    a = a[1:]
                x = maxa
                a = a[1:]
        else:
            ans = abs(last-y)
            flag = True
            break
        if len(a) > 0:
            maxa = max(a)
            mina = min(a)
            if abs(x-last) > abs(x-maxa) and abs(x-last) > abs(x-mina):
                if abs(x-maxa) < abs(x-mina):
                    while a[0] != maxa:
                        a = a[1:]
                    y = maxa
                    a = a[1:]
                else:
                    while a[0] != mina:
                        a = a[1:]
                    y = mina
                    a = a[1:]
            else:
                ans = abs(x-last)
                flag = True
                break

    if flag:
        print(ans)
    else:
        print(abs(x-y))
else:
    print(abs(a[0]-y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 0
for a in al:
    ans = max(ans, abs(al[-1]-a))

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for a in al:
    ans = max(ans, abs(al[-1]-a))

ans = max(ans, abs(w-al[-1]))

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,Z,W=map(int,input().split())
a=list(map(int,input().split()))
res = abs(a[-1]-W)
for i in range(n-1):
    x = a[i]
    la = [abs(a[j]-x) for j in range(i+1,n)]
    if la:
        if min(la) == la[-1]:
            res = max(res,la[-1])
print(res)

Submission status: Wrong Answer

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):
        hoge = min(hoge,abs(a[i]-a[j]))
    ans = max(ans,hoge)
print(ans)

Submission status: Wrong Answer

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[i]-a[j]))
    ans = max(ans,hoge)
print(ans)

Submission status: Wrong Answer

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

N,X,Y=map(int, sys.stdin.readline().split())
A=[None]+map(int, sys.stdin.readline().split())

#Xさんがi枚目を最後に取り、Yさんがj枚目を最後に取った状態のスコアで全状態を表せる
dp=[ [0 for j in range(N+1)] for i in range(N+1) ] 

#初期化
for i in range(N+1):
    for j in range(1,N+1):
        if i>=j:
            dp[i][j]=None
for j in range(1,N+1):
    dp[0][j]=None

dp[0][0]=abs(X-Y)


for i in range(1,N+1):
    for j in range(N+1):
        if j==0:
            dp[i][j]=abs(Y-A[i])
        elif dp[i][j] is None:
            continue
        else:
            dp[i][j]=abs(A[j]-A[i])


ans=float("-inf")
for i in range(N+1):
    if dp[i][N] is not None:
        ans=max(ans,dp[i][N])

for j in range(N+1):
    if dp[N][j] is not None:
        ans=max(ans,dp[N][j])

print ans

Submission status: Wrong Answer

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

N,X,Y=map(int, sys.stdin.readline().split())
A=[None]+map(int, sys.stdin.readline().split())

#Xさんがi枚目を最後に取り、Yさんがj枚目を最後に取った状態のスコアで全状態を表せる
dp=[ [0 for j in range(N+1)] for i in range(N+1) ] 

#初期化
for i in range(N+1):
    dp[i][i]=None
    dp[i][1]=None
for j in range(1,N+1):
    dp[N][j]=None
    dp[0][j]=None

dp[0][0]=abs(X-Y)


for i in range(1,N+1):
    for j in range(N+1):
        if j==0:
            dp[i][j]=abs(Y-A[i])
        elif dp[i][j] is None:
            continue
        else:
            dp[i][j]=abs(A[j]-A[i])


ans=float("-inf")
for i in range(N+1):
    if dp[i][N] is not None:
        ans=max(ans,dp[i][N])

for j in range(N+1):
    if dp[N][j] is not None:
        ans=max(ans,dp[N][j])

print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n,z,w=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    print(abs(a[0]-w))
    sys.exit()
if n==2:
    print(max(abs(a[1]-w),abs(a[0]-a[1])))
    sys.exit()
lst=[0]*n
m=[0]*n
lst[n-1]=abs(a[n-1]-w)
m[n-1]=lst[n-1]
lst[n-2]=abs(a[n-1]-a[n-2])
m[n-2]=lst[n-2]
lst[n-3]=min(abs(a[n-1]-a[n-3]),lst[n-2])
m[n-3]=max(lst[n-2],lst[n-3])
for i in range(4,n+1):
    k=i
    i=n-i
    ans=min(abs(a[n-1]-a[i]),m[n-2])
    for j in range(1,k-2):
        b=max(abs(a[i+j]-a[n-1]),m[i+j+1])
        ans=min(ans,b)
    m[i]=max(ans,m[i+1])
print(lst)
print(m)
print(max(m[0],m[-1]))

Submission status: Wrong Answer

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 a_ls[-1] - w < a_ls[-2] - a_ls[-1]:
    x = a_ls[-2]
    y = a_ls[-1]
else:
    x = a_ls[-1]
    y = w
print(x - y)

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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()]
INF = 1e10
_max = -INF
_min = INF
max_ls = []
min_ls = []
for a in a_ls[::-1]:
    if a >= _max:
        _max = a
        max_ls.append(_max)
    if a <= _min:
        _min = a
        min_ls.append(_min)
max_ls = max_ls[::-1]
min_ls = min_ls[::-1]
last_z = z
last_w = w
while len(max_ls) > 0 and len(min_ls) > 0:
    max_candidate = max_ls[0]
    min_candidate = min_ls[0]
    if abs(max_candidate - last_w) > abs(min_candidate - last_w):
        last_z = max_candidate
        max_ls.pop(0)
        if len(max_ls) == 0:
            break
        else:
            last_w = max_ls[0]
        max_ls.pop(0)
    else:
        last_z = min_candidate
        min_ls.pop(0)
        if len(min_ls) == 0:
            break
        else:
            last_z = min_ls[0]
        min_ls.pop(0)
print(abs(last_z - last_w))

Submission status: Wrong Answer

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()]
INF = 1e10
_max = a_ls[-1]
_min = a_ls[-1]
max_ls = []
min_ls = []
for a in a_ls[::-1]:
    if a >= _max:
        _max = a
        max_ls.append(_max)
    if a <= _min:
        _min = a
        min_ls.append(_min)
max_ls = max_ls[::-1]
min_ls = min_ls[::-1]
last_z = z
last_w = w
while len(max_ls) > 0 and len(min_ls) > 0:
    max_candidate = max_ls[0]
    min_candidate = min_ls[0]
    if abs(max_candidate - last_w) > abs(min_candidate - last_w):
        last_z = max_candidate
        max_ls.pop(0)
        if len(max_ls) == 0:
            break
        else:
            last_w = max_ls[0]
        max_ls.pop(0)
    else:
        last_z = min_candidate
        min_ls.pop(0)
        if len(min_ls) == 0:
            break
        else:
            last_z = min_ls[0]
        min_ls.pop(0)
print(abs(last_z - last_w))

Submission status: Wrong Answer

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