#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct SegmentTree{ using F=function; private: int sz; vector seg; Monoid query(int a,int b,int k,int l,int r){ if(a<=l and r<=b) return seg[k]; if(b<=l or r<=a) return M0; Monoid L=query(a,b,2*k,l,(l+r)/2); Monoid R=query(a,b,2*k+1,(l+r)/2,r); return f(L,R); } template int find_first(int a,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz; } int m=(l+r)/2; if(m<=a) return find_first(a,check,acc,2*k+1,m,r); if(a<=l and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_first(a,check,acc,2*k+0,l,m); if(x>=0) return x; return find_first(a,check,acc,2*k+1,m,r); } template int find_last(int b,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz+1;//ここはfalse, +1した位置はtrue } int m=(l+r)/2; if(b<=m) return find_last(b,check,acc,2*k,l,m); if(r<=b and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_last(b,check,acc,2*k+1,m,r); if(x>=0) return x; return find_last(b,check,acc,2*k,l,m); } public: F f; Monoid M0;// モノイドの元 SegmentTree(int n,F f,Monoid M0):f(f),M0(M0){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,Monoid x){ k+=sz; seg[k]=x; k>>=1; for(;k;k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } Monoid query(int a,int b){ return query(a,b,1,0,sz); } // http://codeforces.com/contest/914/submission/107505449 // max x, check(query(a, x)) = true template int find_first(int a,const C &check){ Monoid val=M0; return find_first(a,check,val,1,0,sz); } // http://codeforces.com/contest/914/submission/107505582 // min x, check(query(x, b)) = true template int find_last(int b,C &check){ Monoid val=M0; return find_last(b,check,val,1,0,sz); } }; template struct BinaryTrieMonoid{ private: struct Node{ Node *nxt[2]; Monoid val; Node(Monoid val):nxt{nullptr,nullptr},val(val){} }; Node *root; using F=function; F f; const Monoid e; Monoid query(BitType a,BitType b,Node *cur,BitType l,BitType r,int dep,BitType xor_val){ if(a<=l and r<=b) return (cur?cur->val:e); if(dep<0 or b<=l or r<=a or !cur) return e; bool x0=(xor_val>>dep)&1; Monoid L=query(a,b,cur->nxt[x0],l,(l+r)/2,dep-1,xor_val); Monoid R=query(a,b,cur->nxt[x0^1],(l+r)/2,r,dep-1,xor_val); return f(L,R); } void update(Node *cur,Monoid x,BitType bit,int dep){ if(dep==-1){ cur->val=x; return ; } bool go_to=(bit>>dep)&1; if(!cur->nxt[go_to]) cur->nxt[go_to]=new Node(e); update(cur->nxt[go_to],x,bit,dep-1); cur->val=f(cur->nxt[0]?cur->nxt[0]->val:e,cur->nxt[1]?cur->nxt[1]->val:e); return ; } public: BinaryTrieMonoid(F f,const Monoid &e):root(new Node(e)),f(f),e(e){} // fold [l,r) // xor_valを指定したとき,可換じゃない演算だと壊れると思います.多分 Monoid query(BitType l,BitType r,BitType xor_val=0){ return query(l,r,root,0,BitType(1)<> dp(5001); // vector> seg_l(5001,SegmentTree(5001,func,0)),seg_r(5001,SegmentTree(5001,func,0)); vector> seg_l(5001,BinaryTrieMonoid(func,0)),seg_r(5001,BinaryTrieMonoid(func,0)); void solve(){ int n;ll x;cin>>n>>x; vector v(n); cin>>v; vector s(n); s[0]=v[0]; for(int i=1;i>n>>x; vector v(n); cin>>v; for(int w=2;w<=n;w++){ for(int l=0;l+w<=n;l++){ int r=l+w;// [l,r) bool win=false; // left { ll s=v[l]; for(int i=l+1;il and s<=x;i--){ if(!dp[l][i]) win=true; s+=v[i-1]; } } dp[l][r]=win; } } cout<<(dp[0][n]?"A":"B")<