#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[100000]; 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; } int v = 0, ng_cnt = 0, ma = 0; int l = 0, r = 0; std::map mp; // clang-format off #define add(idx) {v += a[idx]; mp[a[idx]]++; if (mp[a[idx]] >= 2) ng_cnt++; idx++;} #define remove(idx) {v -= a[idx]; mp[a[idx]]--; if (mp[a[idx]] == 1) ng_cnt--; idx++;} #define evaluate() ((ng_cnt > 0 || v > w) ? -1 : 0) #define consume() {if (r - l > ma) ma = r - l;} // clang-format on if (r <= n) add(r); do { int e = evaluate(); if (ng_cnt > 0 || v > w) remove(l) else { if (e == 0) consume() if (r <= n - 1) add(r) else remove(l) } if (l == r && r <= n - 1) add(r) } while (l < n && r <= n); if (ma == 0) { putc_unlocked('0', stdout); } else { char buf[9]; n = 0; wt_int(ma, buf, n); } return 0; }