/** * @FileName a.cpp * @Author kanpurin * @Created 2020.08.10 04:37:44 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n,w;cin >> n >> w; vector a(n),b; map mp; for (int i = 0; i < n; i++) { cin >> a[i]; if (mp.find(a[i]) == mp.end()) { mp[a[i]] = b.size(); b.push_back(0); } } int r = 0; int ans = 0; ll sum = 0; for (int l = 0; l < n; l++) { while(r < n && b[mp[a[r]]] == 0 && sum + a[r] <= w) { b[mp[a[r]]] = 1; sum += a[r]; r++; } ans = max(ans,r-l); if (r == l) r++; else { sum -= a[l]; b[mp[a[l]]] = 0; } } cout << ans << endl; return 0; }