#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int main() { ll N, W; cin >> N >> W; ll A[N]; for (int i = 0; i < N; ++i) { cin >> A[i]; } int ans = 0; int left = 0; int right = 0; map counter; counter[A[0]]++; ll sum = A[0]; while (left <= right) { if (sum <= W && counter[A[right]] <= 1) { ans = max(ans, right - left + 1); } if (right == N - 1) { counter[A[left]]--; sum -= A[left]; ++left; } else if (counter[A[right]] >= 2) { counter[A[left]]--; sum -= A[left]; ++left; } else if (left == right) { ++right; counter[A[right]]++; sum += A[right]; } else if (sum > W) { counter[A[left]]--; sum -= A[left]; ++left; } else { ++right; counter[A[right]]++; sum += A[right]; } } cout << ans << endl; return 0; }