/* -*- coding: utf-8 -*- * * 1148.cc: No.1148 土偶Ⅲ - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N], uas[MAX_N], bs[MAX_N]; ll ass[MAX_N + 1]; bool used[MAX_N]; /* subroutines */ /* main */ int main() { int n, w; scanf("%d%d", &n, &w); for (int i = 0; i < n; i++) { scanf("%d", as + i); ass[i + 1] = ass[i] + as[i]; uas[i] = as[i]; } sort(uas, uas + n); int m = unique(uas, uas + n) - uas; for (int i = 0; i < n; i++) bs[i] = lower_bound(uas, uas + m, as[i]) - uas; int maxl = 0; for (int i = 0, j = 0; i < n; i++) { while (j < n && ! used[bs[j]] && ass[j + 1] - ass[i] <= w) used[bs[j++]] = true; int l = j - i; if (maxl < l) maxl = l; used[bs[i]] = false; } printf("%d\n", maxl); return 0; }