#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n, w; scanf("%lld %lld", &n, &w); vector a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); set s; int rg = 0; ll res = 0; ll sc = 0; for (int lf = 0; lf < n; lf++) { while (rg < n and s.find(a[rg]) == s.end() and sc + a[rg] <= w) { sc += a[rg]; s.emplace(a[rg]); rg++; } chmax(res, (ll)(rg - lf)); if (lf == rg)rg++; else { sc -= a[lf]; s.erase(s.find(a[lf])); } } cout << res << endl; return 0; }