Created
November 11, 2017 14:21
-
-
Save mi6112ogit/ea5b66baae10a05b61a0b98e51bda1bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
//#define int long long | |
#define FOR(i, j, k) for(int i = j; i < k; ++i) | |
#define rep(i, j) FOR(i, 0, j) | |
#define INF (1 << 30) | |
#define fi first | |
#define se second | |
typedef unsigned long long ull; | |
typedef pair<int, int> P; | |
typedef pair<P, int> Pi; | |
typedef pair<P, P> PP; | |
const int MOD = 1e9 + 7; | |
const int dy[]={0, 0, 1, -1}; | |
const int dx[]={1, -1, 0, 0}; | |
template <class T> void chmin(T& a, const T& b) { a = min(a, b); } | |
template <class T> void chmax(T& a, const T& b) { a = max(a, b); } | |
int n, z, w; | |
int a[2000]; | |
int memo[2001][2]; | |
int solve(int c, int f, int x, int y) { | |
if(c == n) return abs(x - y); | |
if(memo[c][f] >= 0) return memo[c][f]; | |
int ret; | |
if(f) { | |
ret = INF; | |
FOR(i, c, n) ret = min(ret, solve(i + 1, 0, x, a[i])); | |
} | |
else { | |
ret = 0; | |
FOR(i, c, n) ret = max(ret, solve(i + 1, 1, a[i], y)); | |
} | |
return memo[c][f] = ret; | |
} | |
signed main() { | |
cin.tie(0); | |
ios::sync_with_stdio(false); | |
cin >> n >> z >> w; | |
rep(i, n) cin >> a[i]; | |
memset(memo, -1, sizeof(memo)); | |
if(n == 1) cout << abs(a[0] - w) << endl; | |
else cout << solve(0, 0, z, w) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment