#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; int dp[5050][5050]; int s1[5050][5050]; int s2[5050][5050]; ll a[5050]; ll s[5050]; int n; ll x; int solve(int l, int r){ if(dp[l][r]!=-1) return dp[l][r]; if(l==r){ dp[l][r]=1; s1[l][r]=s2[l][r]=1; return 1; } solve(l+1, r); solve(l, r-1); int k=upper_bound(s, s+n+1, s[l]+x)-s; k-=2; k=min(k, r-1); if(s1[l+1][r]-s1[k+2][r]>0){ dp[l][r]=0; s1[l][r]=s1[l+1][r]+dp[l][r]; s2[l][r]=s2[l][r-1]+dp[l][r]; return dp[l][r]; } k=lower_bound(s, s+n+1, s[r+1]-x)-s; k=max(k, l+1); if(s2[l][r-1]-s2[l][k-2]>0){ dp[l][r]=0; }else{ dp[l][r]=1; } s1[l][r]=s1[l+1][r]+dp[l][r]; s2[l][r]=s2[l][r-1]+dp[l][r]; return dp[l][r]; } int main() { int n; ll x; cin>>n>>x; for(int i=0; i>a[i]; s[i+1]=s[i]+a[i]; } for(int i=0; i