forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd.py
More file actions
executable file
·29 lines (25 loc) · 668 Bytes
/
Copy pathd.py
File metadata and controls
executable file
·29 lines (25 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python2
# https://abc078.contest.atcoder.jp/tasks/arc085_b
import sys
sys.setrecursionlimit(10000)
cm = None
cM = None
def m(a, n, i, w):
if w in cm[i]: return cm[i][w]
m = abs(a[n - 1] - w)
for k in range(i, n - 1):
m = min(m, abs(M(a, n, k + 1, a[k])))
cm[i][w] = m
return m
def M(a, n, i, w):
if w in cM[i]: return cM[i][w]
M = abs(a[n - 1] - w)
for k in range(i, n - 1):
M = max(M, abs(m(a, n, k + 1, a[k])))
cM[i][w] = M
return M
n, z, w = map(int, raw_input().split())
a = map(int, raw_input().split())
cm = [dict() for _ in range(n)]
cM = [dict() for _ in range(n)]
print M(a, n, 0, w)