Problem:


Score : 500 points

Problem Statement

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

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

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

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

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

Constraints

All input values are integers.

1 \leq N \leq 2000

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

Input

Input is given from Standard Input in the following format:

N Z W
a_1 a_2 ... a_N

Output

Print the score.

Sample Input 1

3 100 100
10 1000 100

Sample Output 1

900

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

Sample Input 2

3 100 1000
10 100 100

Sample Output 2

900

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

Sample Input 3

5 1 1
1 1 1 1 1

Sample Output 3

0

Sample Input 4

1 1 1
1000000000

Sample Output 4

999999999



Sample input:
3 100 100
10 1000 100


Sample output:
900

Submission status: Wrong Answer

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

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

p = 0
i = 0
flag = 0
while i < N:
    if p == 0:
        if a[i] > Z:
            Z = a[i]
            i += 1
            flag = 0
            p = 1
        elif a[i] < W:
            if flag == 0:
                i += 1
            else:
                flag = 0
                p = 1
        else:
            i += 1
            flag = 1
    else:
        if a[i] < W:
            W = a[i]
            i += 1
            flag = 0
            p = 0
        elif a[i] > Z:
            if flag == 0:
                i += 1
            else:
                flag = 0
                p = 0
        else:
            i += 1
            flag = 1

result = (Z - W) if Z > W else (W - Z)

print(result)

Submission status: Wrong Answer

Solution code:
def getNum():
    N,Z,W = map(int,input().split())
    cards = input()
    cards = cards.split()
    return N,Z,W,cards

def cal(N,Z,W,cards):
    if len(cards) > 1:
        cand1 = abs(W - int(cards[-1]))
        cand2 = abs(int(cards[-1]) - int(cards[-2]))
        if cand1 >= cand2:
            print(cand1)
        else:
            print(cand2)
    else:
        cand1 = abs(W - int(cards[-1]))
        cand2 = abs(Z - int(cards[-1]))
        if cand1 >= cand2:
            print(cand1)
        else:
            print(cand2)

def main():
    N,Z,W,cards = getNum()
    cal(N,Z,W,cards)

main()

Submission status: Wrong Answer

Solution code:
def getNum():
    N,Z,W = map(int,input().split())
    cards = input()
    cards = cards.split()
    print(cards)
    return N,Z,W,cards

def cal(N,Z,W,cards):
    if len(cards) >= 2:
        cand1 = abs(W - int(cards[-1]))
        cand2 = abs(int(cards[-1]) - int(cards[-2]))
        if cand1 >= cand2:
            print(cand1)
        else:
            print(cand2)
    else:
        cand1 = abs(W - int(cards[-1]))
        cand2 = abs(Z - int(cards[-1]))
        if cand1 >= cand2:
            print(cand1)
        else:
            print(cand2)

def main():
    N,Z,W,cards = getNum()
    cal(N,Z,W,cards)

main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

line = input().rstrip().split()
N = int(line[0])
X = int(line[1])
Y = int(line[2])

list = input().rstrip().split()

now = -1

def turn_x(tmp):
    global X
    store = tmp + 1
    max = abs(Y - int(list[store]))
    if store == N-1:
        X = int(list[store])
        return store
    else:
        for work in range(tmp+2,N):
            if max < abs(Y - int(list[work])):
                store = work
                max = abs(Y - int(list[work]))
                X = int(list[work])
        return store
    
def turn_y(tmp):
    global Y
    store = tmp + 1
    min = abs(X - int(list[store]))
    if store == N-1:
        Y = int(list[store])
        return store
    else:
        for work in range(tmp+2,N):
            if min > abs(X - int(list[work])):
                store = work
                min = abs(X - int(list[work]))
                Y = int(list[work])
        return store

while now < N-1:
    now = turn_x(now)
    if now ==N-1:
        break
    else:
        now = turn_y(now)

print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
n,z,w = map(int, raw_input().split())
l = map(int, raw_input().split())
ret = 0
for i in range(n):
    s = 10**10
    if i == n-1:
        s = min(s, abs(l[i] - w))
    else:
        for j in range(i+1,n):
            s = min(s, abs(l[i]-l[j]))
    ret = max(ret, s)
print ret

Submission status: Wrong Answer

Solution code:
import sys

N, Z, W = map(int, input().split())
aList = list(map(int, input().split()))
aMax = max(aList)
aMin = min(aList)

if abs(aMax - W) > abs(aMin - W) and abs(aMax - W) > abs(Z - W):
    idx = aList.index(aMax)
    newList = aList[idx+1:]
    if len(newList) == 0:
        Z = aMax
        print(abs(Z - W))
        sys.exit()
    newMax = max(newList)
    if abs(aMax - newMax) > abs(Z - W):
        Z = aMax
        W = newMax
else:
    idx = aList.index(aMin)
    newList = aList[idx+1:]
    if len(newList) == 0:
        Z = aMin
        print(abs(Z - W))
        sys.exit()
    newMin = min(newList)
    if abs(aMin - newMin) > abs(Z - W):
        Z = aMin
        W = newMin
print(abs(Z - W))

Submission status: Wrong Answer

Solution code:
l = input().split()
n = int(l[0])
x = int(l[1])
y = int(l[2])

l = input().split()
a = []
for i in range(n):
	a.append(int(l[i]))

turn = True

i = 0
while( i < n ):
	if turn:
		if (a[i] > x) or (i == n-1) :
			x = a[i]
			turn = False
		i += 1

	else:
		if (a[i] < y) or (i == n-1) :
			y = a[i]
			turn = True
		i += 1

if x > y:
	print( x - y )
else:
	print( y - x )

Submission status: Wrong Answer

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

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

main()

Submission status: Wrong Answer

Solution code:
# D問題

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

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

if N == 1:
	ans = abs(a[-1]-W)
else:
	ans = abs(a[-1]-a[-2])


print(ans)

Submission status: Wrong Answer

Solution code:
# D問題

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

a = list(map(int,input().split(" ")))
k = [Z,W]
k.extend(a)

dif = 0
ans = abs(Z-W)
edge = a[-1]
for m in k:
	dif = abs(m-edge)
	if ans < dif:
		ans = dif

print(ans)

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx
    if(turn_x):
        max_dif = -1
        for i in range(now_idx, n):
            if(abs(w - int(an[i])) > max_dif):
                max_dif = abs(w - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx, n):
            if(abs(z - int(an[i])) < min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx + 1
    if(now_idx >= n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx
    if(turn_x):
        max_dif = -1
        for i in range(now_idx, n):
            if(abs(w - int(an[i])) >= max_dif):
                max_dif = abs(w - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx, n):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx + 1
    if(now_idx >= n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx = now_idx
    if(turn_x):
        max_dif = -1
        for i in range(now_idx, n):
            if(abs(z - int(an[i])) >= max_dif):
                max_dif = abs(z - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx, n):
            if(abs(w - int(an[i])) <= min_dif):
                min_dif = abs(w - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx + 1
    if(now_idx >= n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
from collections import deque

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

def ans(a, b):
    print(a - b)

def main():
    deck = deque([])
    deck.extend(DECK)
    first = deck.popleft()

    x = max(Z, first)
    y = W

    deck_max = max(deck) if deck else x
    deck_min = min(deck) if deck else y

    ans(max(x, deck_max), min(y, deck_min))

main()

Submission status: Wrong Answer

Solution code:
N, Z, W = map(int, input().split())
a = [int(n) for n in input().split()]
b = a[-1]
max = 0
for n in a:
    if abs(n - b) > max:
        max = abs(n - b)
if len(a) > 1:
    if abs(n - Z) > max:
        max = abs(n - Z)
if abs(n - W) > max:
    max = abs(n - W)

print(max)

Submission status: Wrong Answer

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


a_max=max(a)
a_min=min(a)
a_last=a[-1]

#answer=abs(a_last-w)
#answer=abs(a_max-a_last) 
answer=abs(a_last-a_min)
print(answer)

Submission status: Wrong Answer

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


a_max=max(a)
a_min=min(a)
a_last=a[-1]

#answer=abs(a_last-w)
answer=abs(a_max-a_last) 
#answer=abs(a_last-a_min)
print(answer)

Submission status: Wrong Answer

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


a_max=max(a)
a_min=min(a)
a_last=a[-1]

answer=abs(a_last-w)
#answer=abs(a_max-a_last) 
#answer=abs(a_last-a_min)
print(answer)

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, raw_input().split())
a = map(int, raw_input().split())
x = a[-1]
best = abs(w - x)
for i in a:
    if abs(i - x) > best:
        best = abs(i - x)
print best

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx= 0
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, n):
            if(abs(w - int(an[i])) >= max_dif):
                max_dif = abs(w - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, n):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

Solution code:
n,x,y = map(int,input().split())
a = map(int,(input().split()))
a = list(a)
x = a[0]
bb = 0
if n == 1:
  x=a[0]
  print(abs(x-y))
else:
  for b in range(n):
    if x < a[b]:
      x = a[b]
      bb = b
  if bb == n:
    print(abs(x-y))
  else:
    bb += 1
    y == a[bb]
    for c in range(n-bb):
      if y < a[bb+c]:
        y = a[bb+c]
    print(abs(x-y))

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx= 0
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, n):
            if(abs(z - int(an[i])) >= max_dif):
                max_dif = abs(z - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, n):
            if(abs(w - int(an[i])) <= min_dif):
                min_dif = abs(w - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, z, w = map(int, input().split())
tmp = list(map(int, input().split()))
a = np.array(tmp)

if len(a) == 1:
    score = abs(a[0] - w)
else:
    max_ = abs(max(a[:-1]) - a[-1])
    min_ = abs(a[-1] - min(a[1:-1]))
    score = max(max_, min_, abs(max(a[:]) - w))

print(score)

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
for j in range(n):
    tmp_idx= 0
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, n):
            if(abs(w - int(an[i])) >= max_dif):
                max_dif = abs(z - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, n):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == n - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
xy = [Z, W]
a_sorted = sorted(a)
tmp_ind = 0
teban = 0
enemy = 1
xory = 0
while(tmp_ind<N):
    if abs(a_sorted[0]-xy[enemy])>abs(a_sorted[-1]-xy[enemy]):
        xy[teban] = a_sorted[(0+xory)%2]
    else:
        xy[teban] = a_sorted[-((1+xory)%2)]

    new_ind = a[tmp_ind::].index(xy[teban]) + tmp_ind
    '''
    print('new_ind = ' + str(new_ind))
    print('a_sorted = ')
    print(a_sorted)
    '''
    for i in range(tmp_ind, new_ind+1):
        #print('remove of ' + str(a[i]))
        a_sorted.remove(a[i])
    #print(a_sorted)
    tmp_ind = new_ind+1
    teban, enemy = enemy, teban
    xory = (xory+1)%2

print(abs(xy[0]-xy[1]))

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, input().split())
arr = list(map(int, input().split()))
x = z
y = w
idx = 0
M = max(arr)
if M >= x:
    for i in range(len(arr)-1, -1, -1):
        if arr[i] == M:
            idx = i
            x = arr[i]
            break
else:
    idx = 0

if idx+1 != len(arr):
    m = min(arr[idx:])
    if m <= y:
        y = m


print(abs(x-y))

Submission status: Wrong Answer

Solution code:
nzw = input().split()
n = int(nzw[0])
z = int(nzw[1])
w = int(nzw[2])
an = input().split()
turn_x = True
now_idx = 0
while(True):
    tmp_idx= 0
    if(turn_x):
        max_dif = -1
        for i in range(now_idx + 1, len(an)):
            if(abs(z - int(an[i])) >= max_dif):
                max_dif = abs(z - int(an[i]))
                tmp_idx = i
        z = int(an[tmp_idx])
    else:
        min_dif = float("inf")
        for i in range(now_idx + 1, len(an)):
            if(abs(z - int(an[i])) <= min_dif):
                min_dif = abs(z - int(an[i]))
                tmp_idx = i
        w = int(an[tmp_idx])
    now_idx = tmp_idx
    if(now_idx == len(an) - 1):
        break
    turn_x = not(turn_x)
print(abs(z - w))

Submission status: Wrong Answer

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

if z < w:
    z, w = w, z

for i in a:
    if z < i:
        z = i

for i in a[1:]:
    if w > i:
        w = i

x = z - w
if x < 0:
    x *= -1

print(x)

Submission status: Wrong Answer

Solution code:
N, z, w = map(int, input().split())
A = list(map(int, input().split()))
first = A[0]
last = A[-1]
A.pop()
if len(A) != 0:
    A.pop(0)

if len(A) is 0:
    print(abs(last-w))
else:
    print(max(abs(w-last), abs(max(max(A), first)-last), abs(min(A)-last), abs(first-last)))

Submission status: Wrong Answer

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

if z < w:
    z, w = w, z

for i in a:
    if z < i:
        z = i

for i in a[1:]:
    if w > i:
        w = i

print(z - w)

Submission status: Wrong Answer

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

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
X, Y = Z, W

for i in range(0, N):
    X = a[i]
    if(a[i] > Z):
        s = i+1
        break
    else:
        s = len(a)

for i in range(s, N):
    Y = a[i]
    if(a[i] >= W):
        break

print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
N, z, w = map(int, input().split())
A = list(map(int, input().split()))
first = A[0]
last = A[-1]
A.pop()
if len(A) != 0:
    A.pop(0)

if len(A) is 0:
    print(abs(last-w))
else:
    print(max(abs(w-last), abs(max(A)-last), abs(min(A)-last), abs(first-last)))

Submission status: Wrong Answer

Solution code:
N, z, w = map(int, input().split())
A = list(map(int, input().split()))
first = A[0]
last = A[-1]
A.pop()
if len(A) != 0:
    A.pop(0)

if len(A) is 0:
    print(abs(last-w))
else:
    print(max(abs(w-last), abs(max(A)-last), abs(min(A)-last)))

Submission status: Wrong Answer

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

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
X, Y = Z, W

for i in range(0, len(a)):
    X = a[i]
    if(a[i] > Z):
        s = i+1
        break
    else:
        s = len(a)

for i in range(s, len(a)):
    Y = a[i]
    if(a[i] >= W):
        break

print(abs(X-Y))

Submission status: Wrong Answer

Solution code:
#http://abc078.contest.atcoder.jp/
# -*- coding: utf-8 -*-
n, z, w = map(int,input().split())
a = list(map(int,input().split()))

ans = []
ans.append( abs( a[-1] - w ) )
ans.append( abs( max(a) - a[-1] ) )
ans.append( abs( min(a) - a[-1] ) )

print(max(ans))

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, input().split())
arr = list(map(int, input().split()))
x = z
y = w
idx = 0
for i in range(len(arr)):
    if arr[i] >= x:
        x = arr[i]
        idx = i
for i in range(idx+1, len(arr)):
    if arr[i] < y:
        y = arr[i]
print(abs(x-y))

Submission status: Wrong Answer

Solution code:
N, z, w = map(int, input().split())
A = list(map(int, input().split()))
last = A[-1]
A.pop()

if len(A) is 0:
    print(abs(last-w))
else:
    print(max(abs(w-last), abs(max(A)-last), abs(min(A)-last)))

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
try:
    print(max(abs(max(a[1], b[-2]) - min(a[2], b[-1])), abs(min(a[1], b[-2]) - max(a[2], b[-1]))))
except:
    print(abs(a[1] - b[0]))

Submission status: Wrong Answer

Solution code:
n,z,w=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a_max=max(a)
a_min=min(a)



a_last=a[-1]
 
answer=min(abs(a_last-w), abs(a_max-a_last), abs(a_last-a_min))
 
print(answer)

Submission status: Wrong Answer

Solution code:
N, z, w = map(int, input().split())
A = list(map(int, input().split()))
last = A[-1]
A.pop()

if len(A) is 0:
    print(abs(last-w))
else:
    print(abs(max(w-last, max(A)-last, min(A)-last)))

Submission status: Wrong Answer

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

N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
X, Y = Z, W

for i in range(0, len(a)):
    X = a[i]
    if(a[i] > Z):
        s = i+1
        break
    else:
        s = len(a)

for i in range(s, len(a)):
    Y = a[i]
    if(a[i] > W):
        break

print(abs(X-Y))

Submission status: Wrong Answer

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

if len(a) == 1:
    score = abs(a[0] - w)
else:
    max_ = abs(max(a[:-1]) - a[-1])
    min_ = abs(a[-1] - min(a[1:]))
    score = max(max_, min_, abs(max(a[:]) - w))

print(score)

Submission status: Wrong Answer

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

a_max=max(a)
a_min=min(a)
a_last=a[-1]
#print(a_max,a_min,a_last)

answer=max(abs(a_last-w), abs(a_max-a_last), abs(a_last-a_min))

print(answer)

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=0
for i in range(n-1):
    x=abs(l[-1]-l[i])
    if(x>ans):
        ans=x
y=abs(l[-1]-w)
print max(y,ans)

Submission status: Wrong Answer

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


def solve(small, large, p, n):
    for a in range(len(A)-1):
        if p == 1:
            if small > A[a]:
                small = A[a]
                p = -1
        else:
            if large < A[a]:
                large = A[a]
                p = 1
    if p == 1:
        small = A[-1]
    else:
        large = A[-1]
    return abs(large - small)


print(max(solve(z, w, 1, 1), solve(w, z, 1, 2), solve(z, w, -1, 3), solve(w, z, -1, 4)))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

def main():
    n, z, w = list(map(int, input().split()))
    As = list(map(int, input().split()))
    if len(As) > 1:
        answer = min(max(abs(w - As[-1]), abs(As[-1] - As[-2])), abs(w - As[-2]))
    else:
        answer = abs(w-As[-1])
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=[]
a=max(l)
if(l[-1]==a):
    b=w
    ans.append(abs(a-b))
else:
    b=l[-1]
    ans.append(abs(b-a))
c=min(l)
if(l[-1]==c):
    b=w
    ans.append(abs(c-b))
else:
    b=l[-1]
    ans.append(abs(b-c))

ans.append(abs(l[-1]-w))
print max(ans)

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, input().split())
a = list(map(int, input().split()))
ans = []
# X
ans.append(abs(a[-1]-w))
# XY
if len(a) >= 2:
    for i in range(len(a)-1):
        ans.append(abs(a[i] - a[-1]))
# XYX
if len(a) >= 3:
    for i in range(1, len(a)-1):
        ans.append(abs(a[-1] - a[i]))
print(max(ans))

Submission status: Wrong Answer

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

score = 0
for i in range(1, n):
    score = max(score, abs(max(a[:i])-min(a[i:])))
score = max(score, abs(max(a[:])-w))

print(score)

Submission status: Wrong Answer

Solution code:
n,z,w=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=[]
a=max(l)
if(l[-1]==a):
    b=w
    ans.append(abs(a-b))
else:
    b=l[-1]
    ans.append(abs(b-a))
c=min(l)
if(l[-1]==c):
    b=w
    ans.append(abs(c-b))
else:
    b=l[-1]
    ans.append(abs(b-c))
print max(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import numpy as np
import bisect

N , Z ,W = input().split()
N = int(N)
Z = int(Z)
W = int(W)
a = input().split()
a = [int(i) for i in reversed(a)]

rst = [ np.abs(W - a[0]) ]
for i in range(N) : 
    rst.append( np.abs(a[i] - a[0]))
    
print(max(rst))

Submission status: Wrong Answer

Solution code:
import sys

def get_Y(array, num):
    tmp = 10**9
    for a in array:
        d = abs(num - a)
        if tmp > d:
            tmp = d
    return d

N, Z, W = list(map(int, sys.stdin.readline().strip().split(" ")))
a_list = list(map(int, sys.stdin.readline().strip().split(" ")))

tmp = 0
for i, x in enumerate(a_list):
    if i != (len(a_list)-1):
        dd = get_Y(a_list[(i+1):], x)
        if tmp < dd:
            tmp = dd
D = abs(a_list[-1] - W)
print(str(max(D, tmp)))

Submission status: Wrong Answer

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


def solve(small, large, p):
    for a in A:
        if p == 1:
            if large < a:
                large = a
                p = -1
        else:
            if small > a:
                small = a
                p = 1
    return [small, large]

ans = solve(z, w, 1)
print(max(ans)-min(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**6)
INF = 10**12
N, Z, W = map(int, input().split())
a = [Z] + list(map(int, input().split()))

def rec(X,Y,i,count):# i枚目まで取った
    if i == N:# 山札がないので得点計算して更新
        return abs(X-Y)
    else:
        if count % 2 == 0:# 今はXのターン
            tmp = -INF
            for j in range(i+1,N+1):
                tmp = max(tmp, rec(a[j], Y, j, count+1))
            return tmp
        else:# 今はYのターン
            tmp = INF
            for j in range(i+1,N+1):
                tmp = min(tmp, rec(X, a[j], j, count+1))
            return tmp

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

Submission status: Time Limit Exceeded

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

sys.setrecursionlimit(10**6)
INF = 10**12

N, Z, W = map(int, input().split())
a = [Z] + list(map(int, input().split()))
# print(a)

def rec(X,Y,i,count):# i枚目まで取った
    if i == N:# 山札がないので得点計算して更新
        return abs(X-Y)
    else:
        if count % 2 == 0:# 今はXのターン
            tmp = []
            for j in range(i+1,N+1):
                # print(i,j,count)
                tmp.append(rec(a[j], Y, j, count+1))
            return max(tmp)
        else:# 今はYのターン
            tmp = []
            for j in range(i+1,N+1):
                # print(i,j,count)
                tmp.append(rec(X, a[j], j, count+1))
            return min(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,z,w = list(map(int, input().split()))
a = list(map(int, input().split()))
dx = [[None]*(n+1) for _ in range(n+1)]
dy = [[None]*(n+1) for _ in range(n+1)]
def subx(zz, i):
    if dx[zz][i] is not None:
        return dx[zz][i]
    v = w if i==0 else a[i-1]
    if i==n:
        vv = z if zz==0 else a[zz-1]
        val = abs(v-vv)
    else:
        val = max(suby(i, ii+1) for ii in range(i, n))
    dx[zz][i] = val
    return val
def suby(ww, i):
    if dy[ww][i] is not None:
        return dy[ww][i]
    v = z if i==0 else a[i-1]
    if i==n:
        vv = w if ww==0 else a[ww-1]
        val = abs(v-vv)
    else:
        val = min(subx(i, ii+1) for ii in range(i, n))
    dy[ww][i] = val
    return val
ans = subx(0,0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,z,w = list(map(int, input().split()))
a = list(map(int, input().split()))
dx = {}
dy = {}
def subx(zz, i):
    if (zz,i) in dx:
        return dx[zz,i]
    v = w if i==0 else a[i-1]
    if i==n:
        val = abs(v-zz)
    else:
        val = max(suby(v, ii+1) for ii in range(i, n))
    dx[zz,i] = val
    return val
def suby(ww, i):
    if (ww,i) in dy:
        return dy[ww,i]
    v = z if i==0 else a[i-1]
    if i==n:
        val = abs(v-ww)
    else:
        val = min(subx(v, ii+1) for ii in range(i, n))
    dy[ww,i] = val
    return val
ans = subx(z,0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10**7)

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    """
    O(N^2)dpでも行けるそうです。以下写経：
    https://atcoder.jp/contests/abc078/submissions/14886969
    dpテーブルが訳分からなくなったら@lru_cache使うのが楽。
    """
    @lru_cache(maxsize=None)
    def dfs(turn, top, x, y): # turn: 0 => x, 1 => y
        if top == N: return abs(x - y)
        if turn == 1:
            """
            yのターンは、top以降を取ってなるべくスコアが低くなるようなiを選ぶ
            """
            ret = 10**9
            for i in range(top, N): ret = min(ret, dfs(0, i + 1, x, A[i]))
            return ret
        else:
            """
            xのターンは、top以降を取ってなるべくスコアが高くなるようなiを選ぶ
            """
            ret = 0
            for i in range(top, N): ret = max(ret, dfs(1, i + 1, A[i], y))
            return ret
    
    print(dfs(0, 0, Z, W))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [0] * N

    @lru_cache(maxsize=None)
    def hoge(z, w, n, turn):
        if n == 0:
            return abs(z - w)
        if turn:
            return max(hoge(A[N - 1 - i], w, i, not turn) for i in range(n))
        else:
            return min(hoge(z, A[N - 1 - i], i, not turn) for i in range(n))
    return hoge(Z, W, N, True)

print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)

def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    dp = [0] * N
    def hoge(z, w, n, turn):
        if n == 0:
            return abs(z - w)
        if turn:
            return max(hoge(A[N - 1 - i], w, i, not turn) for i in range(n))
        else:
            return min(hoge(z, A[N - 1 - i], i, not turn) for i in range(n))
    return hoge(Z, W, N, True)

print(main())

Submission status: Time Limit Exceeded

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


def calc(yv, 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 max_value


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