#include #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") 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; } vector> dp(5001); vector> s_l(5001,vector(5001,0)),s_r(5001,vector(5001,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;i0) win=true; } // right { int li=lower_bound(begin(s),end(s),s[r-1]-x+1)-begin(s); // can take [li,r) // int opponent_lose=rt.count(l,l+1,li,r-1); int op=s_l[l][r-1]; if(li) op-=s_l[l][li-1]; if(op>0) win=true; } dp[l][r]=win; if(!win){ s_l[l][r]=s_l[l][r-1]+1; s_r[r][l]=s_r[r][l+1]+1; } } } cout<<(dp[0][n]?"A":"B")<>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")<