#pragma GCC target("avx2") #pragma GCC optimize("O3") #include "bits/stdc++.h" using namespace std; using i64 = long long; template struct Segtree{ int n; T op; vector elm; function f; Segtree(int n, T init, function f, T op = T()) : n(n), op(op), elm(2 * n, init), f(f) { for(int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } Segtree(int n, vector init, function f, T op = T()) : n(n), op(op), elm(2 * n), f(f) { for(int i = 0; i < n; ++i) elm[i + n] = init[i]; for(int i = n - 1; i >= 1; --i) elm[i] = f(elm[2 * i], elm[2 * i + 1]); } void set(int x, T val){ x += n; elm[x] = val; while(x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } void update(int x, T val){ x += n; elm[x] = f(elm[x], val); while(x >>= 1) elm[x] = f(elm[2 * x], elm[2 * x + 1]); } T get(int x, int y) const{ T l = op, r = op; for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){ if(x & 1) l = f(l, elm[x++]); if(!(y & 1)) r = f(elm[y--], r); } return f(l, r); } }; signed main(){ int n, x; cin >> n >> x; vector v(n); for(auto& w : v) cin >> w; vector r(n + 1, 0); for(int i = 0; i < n; ++i) r[i + 1] = r[i] + v[i]; vector nex(n, n), prev(n, 0); for(int i = 0; i < n; ++i){ auto it = upper_bound(r.begin(), r.end(), r[i] + x); int idx = distance(r.begin(), it); nex[i] = min(idx, n); auto it2 = lower_bound(r.begin(), r.end(), r[i + 1] - x); idx = distance(r.begin(), it2); prev[i] = max(0, idx - 1); } /* for(auto& x : nex) cout << x << " "; cout << endl; for(auto& x : prev) cout << x << " "; cout << endl; */ vector> a(n, Segtree(n, 0, [](auto x, auto y){return x + y;}, 0)); vector> b(n, Segtree(n, 0, [](auto x, auto y){return x + y;}, 0)); for(int k = 1; k < n; ++k) for(int i = 0, j = k; j < n; ++i, ++j){ bool f = false; // TODO: set len // dp[i][j] : dp[i][j - x, j) // cout << j - prev[j] << " " << nex[i] - (i + 1) << " "; f |= (a[i].get(max(i, prev[j]), j) != (j - max(i, prev[j]))); // dp[i][j] : dp[i, i + x][j, j) f |= (b[j].get(i + 1, min(nex[i], j + 1)) != (min(nex[i], j + 1) - (i + 1))); if(f){ a[i].update(j, 1); b[j].update(i, 1); } /* cout << "[" << i << ",[" << max(i, prev[j]) << "," << j - 1 << "]] : "; cout << "[[" << i + 1 << "," << min(nex[j], j + 1) - 1 << "]," << j << "] : "; cout << "[" << i << "," << j << "] -> " << (f ? "Win" : "Lose") << endl; */ } /* for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j) cout << a[i].sum(j, j + 1) << " \n"[j == n - 1]; } cout << endl; */ cout << (a[0].get(n - 1, n) ? "A" : "B") << endl; }