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()))
dic = {}
for i in range(n):
    if not a[i] in dic.keys():
        dic[a[i]] = 0
    dic[a[i]] = max(dic[a[i]],i)
sorted_a = sorted(list(set(a)))
x,y = len(sorted_a)-1,0
cnt = -1
while cnt<n-1:
    while True:
        k = sorted_a[x]
        if dic[k]>cnt:
            cnt = dic[k]
            x -= 1
            z = k
            break
        x -= 1
    if cnt==n-1:
        break
    while True:
        k = sorted_a[y]
        if dic[k]>cnt:
            cnt = dic[k]
            y += 1
            w = k
            break
        y += 1
print(abs(z-w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import numpy as np


N,Z,W = map(int, input().split())
An = np.array(list(map(int, sys.stdin.readline().rstrip().split())))

XY = [Z,W]
turn = 0
a = An
while (len(a) > 0):
	if turn%2 == 0:
		itmp = [i for i, x in enumerate(a) if x == max(a)]
		if a[itmp[0]] <= XY[1]:
			idx = itmp[-1]
		else:
			idx = itmp[0]
	else:
		itmp = [i for i, x in enumerate(a) if x == min(a)]
		if a[itmp[0]] >= XY[0]:
			idx = itmp[-1]
		else:
			idx = itmp[0]
	
	XY[turn%2] = a[idx]
	if idx == len(a)-1:
		a = []
	else:
		a = a[idx+1:]
	turn += 1

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

Submission status: Wrong Answer

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import numpy as np


N,Z,W = map(int, input().split())
An = np.array(list(map(int, sys.stdin.readline().rstrip().split())))

XY = [Z,W]
turn = 0
a = An
while (len(a) > 0):
	if turn%2 == 0:
		idx = [i for i, x in enumerate(a) if x == max(a)][-1]
	else:
		idx = [i for i, x in enumerate(a) if x == min(a)][-1]
	
	XY[turn%2] = a[idx]
	if idx == len(a)-1:
		a = []
	else:
		a = a[idx+1:]
	turn += 1
	
print(abs(XY[0]-XY[1]))

Submission status: Wrong Answer

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
from itertools import dropwhile


N,Z,W = map(int, input().split())
An = list(map(int, sys.stdin.readline().rstrip().split()))

XY = [Z,W]
turn = 0
a = An
while (len(a) > 0):
	## a を条件が満たす部分まで飛ばす
	if turn%2 == 0:
		a = list(dropwhile(lambda x:x<=XY[0], a))
	else:
		a = list(dropwhile(lambda x:x>=XY[1], a))

	## XY をマッチした値で置き換え 
	if len(a) > 0:
		XY[turn%2] = a[0]
		a = a[1:]
	else:
		XY[turn%2] = An[-1]

	turn += 1

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

Submission status: Wrong Answer

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
from itertools import dropwhile


N,Z,W = map(int, input().split())
An = list(map(int, sys.stdin.readline().rstrip().split()))

XY = [Z,W]
turn = 0
while (len(An) > 0):
	if turn%2 == 0:
		a = list(dropwhile(lambda x:x<=XY[0], An))
	else:
		a = list(dropwhile(lambda x:x>=XY[1], An))

	if len(a) > 0:
		XY[turn%2] = a[0]
		a = a[1:]
	else:
		XY[turn%2] = An[-1]
	turn += 1
	An = a

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

Submission status: Wrong Answer

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()
mx1 = abs(max(a[0:n-1]) - a[-1])
mx2 = abs(min(a[0:n-1]) - a[-1])
mx3 = abs(a[-1] - w)
mx4 = abs(max(a[1:n-1]) - a[-1])
mx5 = abs(min(a[1:n-1]) - a[-1])

print(max(mx1, mx2, mx3,mx4,mx5))

Submission status: Wrong Answer

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()
mx1 = abs(max(a[0:n-1]) - a[-1])
mx2 = abs(min(a[0:n-1]) - a[-1])
mx3 = abs(a[-1] - w)
print(max(mx1, mx2, mx3))

Submission status: Wrong Answer

Solution code:
A,B,C=map(int,input().split())
N=[ _ for _ in map(int, input().split())]
Max=0
Min=100000000000000000
for i in N:
  if Max<i:
    Max=i
  if Min>i:
    Min=i
if Max<B:
  Max=B
elif Min>C:
  Min=C
print(Max-Min)

Submission status: Wrong Answer

Solution code:
A,B,C=map(int,input().split())
N=[ _ for _ in map(int, input().split())]
Max=0
Min=10000000000
for i in N:
  if Max<i:
    Max=i
  if Min>i:
    Min=i

print(Max-Min)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:



def get_max(a, n, x, y):
    m=0
    for i in range(n):
        v=abs(a[i] - y)
        if v>m:
            m=v
    return m

def get_min(a, n, x, y):
    m = 999999999999999
    for i in range(n):
        v=abs(x - a[i])
        if v<m:
            m=v
    return m

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

player = 0
draw = 0
min=0
max=get_max(a, n, x, y)

for i in range(n):
    if player == 0:
        if a[i] == max:
            x = a[i]
            player = 1
            min = get_min(a[n-draw-1:], n, x, y)
    else:
        m = min(a[draw: n])
        if a[i] == min:
            y = a[i]
            player = 0
            max = get_max(a[n-draw-1:], n, x, y)
    draw += 1

print(abs(x - y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

player = 0
draw = 0
for i in range(n):
    if player == 0:
        m = max(a[draw: n])
        if a[i] == m:
            x = a[i]
            player = 1
    else:
        m = min(a[draw: n])
        if a[i] == m:
            y = a[i]
            player = 0
    draw += 1

print(abs(x - y))

Submission status: Wrong Answer

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

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

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(X)
#print(Y)
#print(dpX)
#print(dpY) 

curr = 0

while curr<n:
    if X[dpX[curr]]<abs(A[-1]-y):
        curr = n
        x = A[-1]
    else:
        x = A[dpX[curr]]
        curr = dpX[curr]+1
    #print(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)
print(abs(x-y))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

#初手で全部引く
ans1 = max(a)
ans1 = max(ans1,z)-w

#初手で一枚残して引く
if len(a) > 1:
  ans2 = max(a[0:-1])
  ans2 = max(ans2,z)-max(a[-1],w)
else:
  ans2 = -float("inf")

print(max(ans1,ans2))

Submission status: Wrong Answer

Solution code:
class Queue:
    def __init__(self):
        self.__data = []
        self.__count = 0

    def empty(self) -> bool:
        return self.__count == 0

    def enqueue(self, v):
        self.__data.append(v)
        self.__count += 1

    def dequeue(self):
        v = self.__data[0]
        self.__data = self.__data[1:]
        self.__count -= 1
        return v


def _abs(N: int, Z: int, W: int, A: list) -> int:
    # X さんはスコアを最大化したいので、引き始めるところから
    # 見える最大値の位置まで引く。逆に Y さんはスコアを最小
    # 化したいので、引き始めるところから見える最小値の位置ま
    # でひく。問題は、同じ値が連続するところ、例えば
    # A = [1, 2, 3, 1, 2, 3, 1, 2, 3]
    # となっている場合、X さんは 3、 6、 9 番目のカードまで
    # とることができるがそれをどこまで取るべきかを考える必要
    # がある。
    INF = float('inf')

    max_A, min_A = [0] * (N+1), [INF] * (N+1)
    for n, a in enumerate(reversed(A)):
        max_A[N-n-1] = max(a, max_A[N-n])
        min_A[N-n-1] = min(a, min_A[N-n])

    # max_A = max(A)
    turn = 'X'
    idx = 0
    while idx < N:
        # print(A[idx], turn)
        if turn == 'X':
            if max_A[idx] > max_A[idx+1]:
                Z = max_A[idx]
                turn = 'Y'
                # min_A = min(A[idx:])
        else:
            if min_A[idx] < min_A[idx+1]:
                W = min_A[idx]
                turn = 'X'
                # max_A = max(A[idx:])
        idx += 1

    return abs(Z-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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, _, w = map(int, input().split())
a = list(map(int, input().split()))
# case 1: last is y
dp = [[0 for _ in range(2)] for _ in range(n)]
dp[n-1][0] = abs(a[n-2] - a[n-1])
dp[n-1][1] = abs(a[n-2] - a[n-1])
for i in range(n-2, -1, -1):
    dp[i][0] = abs(a[n-1] - a[i])
    dp[i][1] = abs(a[n-1] - a[i])
    for j in range(1, n-i):
        dp[i][0] = max(dp[i][0], dp[i+j][1])
        dp[i][1] = min(dp[i][1], dp[i+j][0])
print(max(dp[0][0], abs(a[n-1] - w)))

Submission status: Wrong Answer

Solution code:
import bisect

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




ans = 0

for i in range(n-1):
    x = A[i]
    B = A[i+1:]
    B.sort()
    bi = bisect.bisect_right(B, x)
    y1 = B[max(0, bi-1)]
    y2 = B[min(bi, len(B)-1)]
    ans = max(ans, min(abs(x-y1), abs(x-y2)))
    
print(max(ans, abs(A[-1]-w)))

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

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

i = 0
while i < len(a):
    while i < len(a):
        head = a[i]
        i += 1
        if z < head:
            z = head
            break

    while i < len(a):
        head = a[i]
        i += 1
        if head < w:
            w = head
            break

print(abs(z - w))

Submission status: Wrong Answer

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

"""
ミニマックス法
"""

import sys
from collections import defaultdict

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

# メモ[手番][残り山札数]{現在のスコア}
memo = [[set() for _ in range(N+1)] for _ in range(2)]

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    if turn % 2 == 0:
        # 訪問済にする
        memo[turn%2][rest].add(abs(x - y))
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            # 既に見た局面でなければ、再帰処理を続ける
            if abs(x - y) not in memo[1-turn%2][N-idx]:
                mx = max(dfs(turn+1, N-idx, x, y), mx)
        return mx
    else:
        memo[turn%2][rest].add(abs(x - y))
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            if abs(x - y) not in memo[1-turn%2][N-idx]:
                mn = min(dfs(turn+1, N-idx, x, y), mn)
        return mn

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

Submission status: Wrong Answer

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

"""
ミニマックス法
"""

import sys
from collections import defaultdict

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

# メモ[手番][残り山札数]{現在の自分のスコア：現在の相手のスコア}
memo = [[defaultdict(set) for _ in range(N+1)] for _ in range(2)]

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    if turn % 2 == 0:
        # 訪問済にする
        memo[turn%2][rest][x].add(y)
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            # 既に見た局面でなければ、再帰処理を続ける
            if x not in memo[1-turn%2][N-idx][y]:
                mx = max(dfs(turn+1, N-idx, x, y), mx)
        return mx
    else:
        memo[turn%2][rest][y].add(x)
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            if y not in memo[1-turn%2][N-idx][x]:
                mn = min(dfs(turn+1, N-idx, x, y), mn)
        return mn

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

Submission status: Wrong Answer

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

"""
ミニマックス法
"""

import sys

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

# メモ[手番][残り山札数]{現在の相手のスコア}
memo = [[set() for _ in range(N+1)] for _ in range(2)]

def dfs(turn, rest, x, y):
    if rest == 0:
        return abs(x - y)
    if turn % 2 == 0:
        # 訪問済にする
        memo[turn%2][rest].add(y)
        mx = -1
        for i in range(N-rest, N):
            x = aN[i]
            idx = i+1
            # 既に見た局面でなければ、再帰処理を続ける
            if x not in memo[1-turn%2][N-idx]:
                mx = max(dfs(turn+1, N-idx, x, y), mx)
        return mx
    else:
        memo[turn%2][rest].add(x)
        mn = float('inf')
        for i in range(N-rest, N):
            y = aN[i]
            idx = i+1
            if y not in memo[1-turn%2][N-idx]:
                mn = min(dfs(turn+1, N-idx, x, y), mn)
        return mn

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

Submission status: Wrong Answer

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

valZ = Z
valW = W
now = 0
t = 0
while 1:
    if t == 0:
        maxA = max(A[now:])
        if maxA == A[-1]:
            valZ = maxA
            break
        else:
            for i in range(N-1,now-1,-1):
                if maxA == A[i]:
                    now = i
                    valZ = A[i]
                    break
    else:
        minA = min(A[now:])
        if minA == A[-1]:
            valW = minA
            break
        else:
            for i in range(N-1,now-1,-1):
                if minA == A[i]:
                    now = i
                    valW = A[i]
                    break
    t = (t+1)%2
print( abs(valZ - valW))

Submission status: Wrong Answer

Solution code:

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

ans=0

for i in range(N):
    if i==N-1:
        if ans<max(abs(a[N-1]-W),abs(a[N-1]-W)):
            ans=max(abs(a[N-1]-W),abs(a[N-1]-W))
    elif abs(a[i]-max(a[i+1:])>abs(a[i]-min(a[i+1:]))):
        if ans<abs(a[i]-max(a[i+1:])):
            ans=abs(a[i]-max(a[i+1:]))
    elif abs(a[i]-max(a[i+1:])<=abs(a[i]-min(a[i+1:]))):
        if ans<abs(a[i]-min(a[i+1:])):
            ans=abs(a[i]-min(a[i+1:]))
print(ans)

Submission status: Wrong Answer

Solution code:
n, z, w = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
k = 0
while a != []:
    if k % 2 == 0:
        for i in range(len(a)):
            if i == 0:
                zc = a[i]
                zcn = i
            elif abs(zc - w) <= abs(a[i] - w):
                zc = a[i]
                zcn = i
        z = zc
        a = a[zcn + 1:]
        k += 1
    else:
        for i in range(len(a)):
            if i == 0:
                wc = a[i]
                wcn = i
            elif abs(wc - z) >= abs(a[i] - z):
                wc = a[i]
                wcn = i
        w = wc
        a = a[wcn + 1:]
        k += 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(a[0] - w)
else:
    print(max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 21 11:28:35 2018
ABC078D
@author: maezawa
"""

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

#if n == 1:
#    cand = [abs(w-a[-1])]
#elif n == 2:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1])]
#elif:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1]), abs(a[-3]-a[-1])]

cand = [abs(w-a[-1])]
for card in a[-4:]:
    cand.append(abs(card-a[-1]))

score = max(cand)
print(score)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 21 11:28:35 2018
ABC078D
@author: maezawa
"""

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

#if n == 1:
#    cand = [abs(w-a[-1])]
#elif n == 2:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1])]
#elif:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1]), abs(a[-3]-a[-1])]

cand = [abs(w-a[-1])]
for card in a[-3:]:
    cand.append(abs(card-a[-1]))

score = max(cand)
print(score)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 21 11:28:35 2018
ABC078D
@author: maezawa
"""

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

#if n == 1:
#    cand = [abs(w-a[-1])]
#elif n == 2:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1])]
#elif:
#    cand = [abs(a[-2]-a[-1]), abs(w-a[-1]), abs(a[-3]-a[-1])]

cand = [abs(w-a[-1])]
for card in a:
    cand.append(abs(card-a[-1]))

score = max(cand)
print(score)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 21 11:28:35 2018
ABC078D
@author: maezawa
"""

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

if n == 1:
    cand = [abs(w-a[-1])]
elif n == 2:
    cand = [abs(a[-2]-a[-1]), abs(w-a[-1])]
else:
    cand = [abs(a[-2]-a[-1]), abs(w-a[-1]), abs(a[-3]-a[-1])]

score = max(cand)
print(score)

Submission status: Wrong Answer

Solution code:
N,Z,W = map(int,input().split())
A = []
A.append(W)
a = list(map(int,input().split()))
for i in range(len(a)) :
    A.append(a[i])
ANS = []
for j in range(len(A)) :
    p = abs(A[-1]-A[j])
    ANS.append(p)

print(max(ANS))

Submission status: Wrong Answer

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

ans = 0

for i in range(N):
	if i != N-1:
		ans = max(ans, min(map(lambda j: abs(a[i]-j), a[i+1:])))
	else:
		ans = max(ans, abs(a[i]-W))

print(ans)

Submission status: Wrong Answer

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

turn = 'x'
while len(a) > 0:
    a_cur = a[0]
    idx = 0
    if turn == 'x':
        score = abs(w - a_cur)
        for i in range(1, len(a)):
            if abs(w - a[i]) >= score:
                a_cur = a[i]
                idx = i
                score = abs(w - a_cur)
        z = a_cur
        turn = 'y'
    else:
        score = abs(z - a_cur)
        for i in range(1, len(a)):
            if abs(z - a[i]) <= score:
                a_cur = a[i]
                idx = i
                score = abs(z - a_cur)
        w = a_cur
        turn = 'x'
    a = a[idx+1:]

print(abs(z - w))

Submission status: Wrong Answer

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

turn = 'x'
while len(a) > 0:
    a_max = a[0]
    idx = 0
    for i in range(1, len(a)):
        if a[i] >= a_max:
            a_max = a[i]
            idx = i
    if turn == 'x':
        z = a_max
        turn = 'y'
    else:
        w = a_max
        turn = 'x'
    a = a[idx+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()]
 
if n == 1:
    print(abs(a[0]) - w)
else:
    print(max(abs(a[n-2]-a[n-1]), abs(a[n-1]-w)))

Submission status: Wrong Answer

Solution code:

n, z, w = map(int, input().split())
#a = [int(x) for x in input().split()]
a = list(map(int, input().split()))

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = [int(x) for x in input().split()]


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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

X = Z
Y = W

# どちらのターンかを判別するフラグ
Xs_turn = True

# カードの枚数ループ
for i in range(N):
    # Xのターン
    if Xs_turn:
        # 最後の1枚の場合を考慮する
        if Z < card_list[i] or i == N - 1:
            X = card_list[i]
            Z = card_list[i]
            Xs_turn = False
        else:
            X = card_list[i]
    # Yのターン
    else:
        if W > card_list[i] or i == N - 1:
            Y = card_list[i]
            W = card_list[i]
            Xs_turn = True
        else:
            Y = card_list[i]
print(abs(X - Y))

Submission status: Wrong Answer

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

N, X, Y = map(int, input().split())
card_list = list(map(int, input().split()))

# どちらのターンかを判別するフラグ
Xs_turn = True

# カードの枚数ループ
for i in range(N):
    # Xのターン
    if Xs_turn:
        # 最後の1枚の場合を考慮する
        if X < card_list[i] or i == N - 1:
            X = card_list[i]
            Xs_turn = False
    # Yのターン
    else:
        if Y > card_list[i] or i == N - 1:
            Y = card_list[i]
            Xs_turn = True
print(abs(X - Y))

Submission status: Wrong Answer

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

N, X, Y = map(int, input().split())
card_list = list(map(int, input().split()))

# どちらのターンかを判別するフラグ
Xs_turn = True

# カードの枚数ループ
for i in range(N):
    # Xのターン
    if Xs_turn:
        if X < card_list[i]:
            X = card_list[i]
            Xs_turn = False
    # Yのターン
    else:
        if Y > card_list[i]:
            Y = card_list[i]
            Xs_turn = True
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:
    print(max(abs(A[-1]-W), abs(A[-2]-A[-1])))

else:
    print(A[-1]-W)

Submission status: Wrong Answer

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

# xさんが最初に持ってるカード:Z
# yさんが最初に持ってるカード:W

a= A+[Z, W]

Amax = max(a)
Amin = min(a)

print(Amax-Amin)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split())) + [Z,W]
amax = max(a)
amin = min(a)
alast = a[N-1]
if N == 1:
    print(abs(W-a[0]))
    exit()
print(max(amax-alast,amin-alast))

Submission status: Wrong Answer

Solution code:
N,Z,W = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
X=a[0]
Y=W
an=a[-1]#n番目　ªの中の最後の値
a1=a[0:-1]#ｎ番目を抜いたリスト
a1W=a1+[W]#ｎ番目を抜いて最後にWを付け足したリスト
X1=an
Y2=an
XYsa=[]
for i in range(N-1):
  XYsa.append(abs(a1W[i]-X1))
for i in range(N):
  XYsa.append(abs(a1W[i]-Y2))
XYsa.sort()
print(XYsa[-1])

Submission status: Wrong Answer

Solution code:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
owa = len(a)
dai = abs(Z-W)
syou = abs(Z-W)
while a:
  for i in range(len(a)):
    if abs(W - a[len(a)-1]) >= abs(min(a) - max(a)):
      Z = a[len(a)-1]
      a =  []
      break
    if dai <= abs(a[i] - W):
      dai = max(abs(a[i] - W),dai)
      iti = i + 0
  if a == []: break
  Z = a[iti]
  if iti == owa: break
  a = a[iti+1:]
  for i in range(len(a)):
    b = sorted(a)
    if b == []: break
    for j in range(len(b)-1):
      b[j] = abs(b[j+1] - b[j])
    b.pop()
    if b == []: break
    if abs(Z - a[len(a)-1]) <= min(b):
      W = a[len(a)-1]
      a =  []
      break
    if dai >= abs(a[i] - Z):
      dai = min(abs(a[i] - Z),dai)
      iti = i + 0
  if b == []: break
  if a == []: break
  W = a[iti]
  if iti == owa: break
  a = a[iti+1:]

print(abs(Z-W))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import os
import sys


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

a = [x for x in map(int, input().split())]

while(len(a)>0):
    z = max(a)
    if len(a) == a.index(z)+1:
        break
    a = a[a.index(z)+1:]
    w = min(a)
    if len(a) == a.index(w)+1:
        break
    a = a[a.index(w)+1:]

print(abs(z-w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A_rev = A[::-1]

i_A_max = N - 1 - A_rev.index(max(A))

X_max = max(Z, max(A[:1+i_A_max]))

try:
    Y_min = min(W, min(A[1+i_A_max:]))
except:
    Y_min = W

print(abs(X_max -Y_min))

Submission status: Wrong Answer

Solution code:
import numpy as np


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

f = []

if N > 2:
    for i in range(0, 2**(N-1)): # 1 枚目は必ず X
        string = str(bin(i))[2:]
        f.append(['1'] + ['0'] * (N - 1 - len(string)) + list(string))
else:
    f = ['1']

F = np.array(f)
F = (F == '1')

R = []

for i in range(len(F)):
    try:
        X_max = max(Z, np.array(A)[F[i]].max())
    except:
        X_max = max(Z, A[0])
    try:
        Y_min = min(W, np.array(A)[F[i]==False].min())
    except:
        Y_min = W
    R.append(abs(X_max-Y_min))

print(max(R))

Submission status: Wrong Answer

Solution code:
import numpy as np


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

f = []

if N > 2:
    for i in range(0, 2**(N-1)): # 1 枚目は必ず X
        string = str(bin(i))[2:]
        f.append(['1'] + ['0'] * (N - 1 - len(string)) + list(string))
else:
    f = ['1']

F = np.array(f)
F = (F == '1')

R = []

for i in range(len(F)):
    try:
        X_max = max(Z, np.array(A)[F[i]].max())
    except:
        X_max = Z
    try:
        Y_min = min(W, np.array(A)[F[i]==False].min())
    except:
        Y_min = W
    R.append(abs(X_max-Y_min))

print(max(R))

Submission status: Wrong Answer

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

# X, Y が両方ひく場合
if len(A) > 2:
    X = max(Z, max(A))
    Y = min(W, min(A[1:]))
else:
    X = max(Z, max(A))
    Y = W

R1 = abs(X - Y)

# X のみ引く場合
X = max(Z, max(A))
Y = W

R2 = abs(X - Y)

print(max(R1, R2))

Submission status: Wrong Answer

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

last_num = nums[-1]
target_num = w
for num in nums:
    if abs(last_num - num) > abs(last_num - target_num):
        target_num = num

print(abs(last_num - target_num))

Submission status: Wrong Answer

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

takeX=0
takeY=0
while takeX < N and takeY<N:
    for j in range(takeX+1, N):
        if cards[takeX] <= cards[j]:
            takeX=j
    Z=cards[takeX]
    if takeX == N-1:
        break
    else:
        takeY=takeX+1
        for j in range(takeY+1, N):
            if cards[takeY] <= cards[j]:
                takeY=j
        W=cards[takeY]
        takeX=takeY+1

print(abs(Z-W))

Submission status: Wrong Answer

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

def takeall(z, w, xs):
    return max(abs(max(xs) - w), abs(min(xs) - w))

def forcelast(z, w, xs):
    return max(abs(max(xs[:-1]) - xs[-1]), abs(min(xs[:-1]) - xs[-1]))

if len(xs) > 1:
    print(max(takeall(z, w, xs), forcelast(z, w, xs)))
else:
    print(takeall(z, w, xs))

Submission status: Wrong Answer

Solution code:
N_X_Y = list(map(int, input().split()))

A = list(map(int,input().split()))
A_max = max(A)
A_min = min(A)

N=[0]*3

N[0]=abs(N_X_Y[2]-A[-1])
N[1]=abs(A_max-A[-1])
N[2]=abs(A_min-A[-1])

print(max(N))

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,z,w]=i2()
a=i2()
ma=[[] for i in range(n)]
mi=[[] for i in range(n)]
ma[-1]=[a[-1],n-1]
mi[-1]=[a[-1],n-1]
for i in range(n-1)[::-1]:
 if a[i]<mi[i+1][0]:
    mi[i]=[a[i],i]
 else:
    mi[i]=mi[i+1]
 if a[i]>ma[i+1][0]:
    ma[i]=[a[i],i]
 else:
    ma[i]=ma[i+1]
def x(i,z,w):
    if i>n-1:
      return z,w
    z=ma[i][0]
    j=ma[i][1]+1
    if j>n-1:
      return z,w
    w=mi[j][0]
    return x(mi[j][1]+1,z,w)
[z,w]=x(0,z,w)
print(abs(z-w))