#include using namespace std; template struct BIT { int n; vector dat; BIT(int n=0){ initialize(n); } void initialize(int nin){ n = nin; dat.resize(n, 0); } T sum(int i){ T s = 0; while(i >= 0){ s += dat[i]; i = (i & (i+1)) - 1; } return s; } T sum_between(int i, int j){ return sum(j) - sum(i-1); } void plus(int i, T x){ while(i < n){ dat[i] += x; i |= i+1; } } // a[0]+...+a[ret] >= x int lower_bound(T x){ if(x < 0) return -1; int ret = -1; int k = 1; while(2*k <= n) k <<= 1; for( ;k>0; k>>=1){ if(ret+k < n && dat[ret+k] < x){ x -= dat[ret+k]; ret += k; } } return ret + 1; } }; int main(){ int N, X; cin >> N >> X; vector A(N), S(N+1); for(int i=0; i> A[i]; S[i+1] = S[i] + A[i]; } vector lnxt(N), rnxt(N); int ng = 0; for(int l=0; l=0; r--){ while(ng >= 0 && S[r]-S[ng] <= X) ng--; rnxt[r] = ng; } BIT bit_L2R[5000], bit_R2L[5000]; for(int i=0; i