#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #include #include #include // clang-format off #define RD(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} // #define RDULL(v) unsigned long long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} // #define wt_int(var,buf,ptr) while(var){buf[ptr++]=var%10;var/=10;}while(ptr--)putc_unlocked(buf[ptr]+'0',stdout); // clang-format on int a[100001]; int main() { char *rp = (char *)mmap(0l, 1l << 28, 1, 2, 0, 0ll); RD(n) RD(w); int *ap = a; for (int i = 0; i < n; ++i) { RD(t); *ap++ = t; } *ap++ = 1000000000 + 9; std::unordered_set st; int left = 0; int sm = 0; int ans = 0; for (int i = 0; i <= n; ++i) { if (st.count(a[i]) > 0 || sm + a[i] > w) { if (i - left > ans) ans = i - left; if (a[i] > sm) { left = i + 1; st.clear(); sm = 0; continue; } while ((st.count(a[i]) > 0 || sm + a[i] > w)) { st.erase(a[left]); sm -= a[left]; left++; } sm += a[i]; st.insert(a[i]); } else { st.insert(a[i]); sm += a[i]; } } if (ans == 0) { putc_unlocked('0', stdout); } else { char buf[9]; n = 0; wt_int(ans, buf, n); } return 0; }