// #define DEBUGGING #include #define endl '\n' #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() using ll = std::int64_t; using ull = std::uint64_t; using PLL = std::pair; using TLL = std::tuple; template using V = std::vector; template using VV = V>; template const T& var_min(const T &t) { return t; } template const T& var_max(const T &t) { return t; } template const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); } template void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } #define mv_rec make_v(init, tail...) template T make_v(T init) { return init; } template auto make_v(T init, size_t s, Tail... tail) { return V(s, mv_rec); } #undef mv_rec using namespace std; #ifdef DEBUGGING #include "../../debug/debug.cpp" #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif const size_t SIZE = 5010; bool calced[SIZE][SIZE][2]; int cnt_r[SIZE], cnt_l[SIZE]; int A[SIZE]; int N, X; struct Bit { int *data; int id_ele = 0; Bit() : Bit(nullptr) { } Bit(int *data) : data(data) { } int sum(int pos) { int ret = id_ele; for(; 0 < pos; pos -= pos & -pos) ret += data[pos]; return ret; } int sum(int l, int r) { if (r <= l) return 0; return sum(r) - sum(l); } void add(int pos, int delta) { for(++pos; pos < SIZE; pos += pos & -pos) data[pos] += delta; } }; void shaku(int max_v[]) { int l = 0, r = 0; int sum = 0; for (int l = 0; l < N; l++) { while (r < N && sum + A[r] <= X) { sum += A[r]; r++; } max_v[l] = r - l; sum -= A[l]; } } int bit_arr[2][SIZE][SIZE]; Bit bit_l[SIZE], bit_r[SIZE]; int main() { cin >> N >> X; for (int i = 0; i < N; i++) cin >> A[i]; shaku(cnt_r); reverse(A, A + N); shaku(cnt_l); reverse(A, A + N); reverse(cnt_l, cnt_l + N); V bit_l(N), bit_r(N); for (ll i = 0; i < N; i++) { bit_l[i] = Bit(bit_arr[0][i]); bit_r[i] = Bit(bit_arr[1][i]); } int suma[SIZE]; for (int i = 0; i < N; i++) suma[i + 1] = suma[i] + A[i]; for (int len = 1; len <= N; len++) { for (int l = 0; l + len - 1 < N; l++) { int r = l + len - 1; if (suma[r + 1] - suma[l] <= X) continue; { int cnt = bit_r[r].sum(l + 1, l + cnt_r[l]); if (cnt < cnt_r[l] - 1) bit_l[l].add(r, 1); } { int cnt = bit_l[l].sum(r - cnt_l[r] + 1, r); if (cnt < cnt_l[r] - 1) bit_r[r].add(l, 1); } } } cout << (bit_l[0].sum(N - 1, N) == 1 ? "A" : "B") << endl; return 0; }