#include using namespace std; #ifdef LOCAL #include #else #define debug(...) 42 #endif // LOCAL struct ChronoTimer { std::chrono::high_resolution_clock::time_point st; ChronoTimer() { reset(); } void reset() { st = std::chrono::high_resolution_clock::now(); } std::chrono::milliseconds::rep elapsed() { auto ed = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast(ed - st) .count(); } }; /** * @brief Scanner(高速入力) */ struct Scanner { public: explicit Scanner(FILE *fp) : fp(fp) {} template void read(T &t, E &...e) { read_single(t); read(e...); } private: static constexpr size_t line_size = 1 << 16; static constexpr size_t int_digits = 20; char line[line_size + 1] = {}; FILE *fp = nullptr; char *st = line; char *ed = line; void read() {} static inline bool is_space(char c) { return c <= ' '; } void reread() { ptrdiff_t len = ed - st; memmove(line, st, len); char *tmp = line + len; ed = tmp + fread(tmp, 1, line_size - len, fp); *ed = 0; st = line; } void skip_space() { while (true) { if (st == ed) reread(); while (*st && is_space(*st)) ++st; if (st != ed) return; } } template ::value, int> = 0> void read_single(T &s) { skip_space(); if (st + int_digits >= ed) reread(); bool neg = false; if (is_signed::value && *st == '-') { neg = true; ++st; } typename make_unsigned::type y = *st++ - '0'; while (*st >= '0') { y = 10 * y + *st++ - '0'; } s = (neg ? -y : y); } template ::value, int> = 0> void read_single(T &s) { s = ""; skip_space(); while (true) { char *base = st; while (*st && !is_space(*st)) ++st; s += string(base, st); if (st != ed) return; reread(); } } template void read_single(vector &s) { for (auto &d : s) read(d); } }; /** * @brief Printer(高速出力) */ struct Printer { public: explicit Printer(FILE *fp) : fp(fp) {} ~Printer() { flush(); } template void write(const T &t, const E &...e) { if (f) write_single(' '); write_single(t); write(e...); } template void writeln(const T &...t) { write(t...); write_single('\n'); } void flush() { fwrite(line, 1, st - line, fp); st = line; } private: FILE *fp = nullptr; static constexpr size_t line_size = 1 << 16; static constexpr size_t int_digits = 20; char line[line_size + 1] = {}; char *st = line; template void write() {} void write_single(const char &t) { if (st + 1 >= line + line_size) flush(); *st++ = t; } template ::value, int> = 0> void write_single(T s) { if (st + int_digits >= line + line_size) flush(); st += to_chars(st, st + int_digits, s).ptr - st; } void write_single(const string &s) { for (auto &c : s) write_single(c); } void write_single(const char *s) { while (*s != 0) write_single(*s++); } template void write_single(const vector &s) { for (size_t i = 0; i < s.size(); i++) { if (i) write_single(' '); write_single(s[i]); } } }; Scanner scanner = Scanner(stdin); Printer printer = Printer(stdout); void flush() { printer.flush(); } void print() { printer.write('\n'); } template void print(Head &&head, Tail &&...tail) { printer.write(head); if (sizeof...(Tail)) printer.write(' '); print(forward(tail)...); } void read() {} template void read(Head &head, Tail &...tail) { scanner.read(head); read(tail...); } #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ read(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ read(name) #define VV(type, name, h, w) \ vector> name(h, vector(w)); \ read(name) int main(int, char **) { #ifdef LOCAL ChronoTimer chrono; freopen("/home/user/acm/competitve/src/input.txt", "r", stdin); freopen("/home/user/acm/competitve/src/output.txt", "w", stdout); #endif std::cout << fixed << setprecision(12); INT(N, X); VEC(long long, A, N); A.resize(N * 2); std::vector S(N * 2 + 1); for (auto i : views::iota(0, N)) { A[i + N] = A[i]; } for (auto i : views::iota(0, N * 2)) { S[i + 1] = S[i] + A[i]; } debug(A); debug(S); int lo = 0, hi = X; int ans = 0; auto check = [&] (long long x) -> bool { for (auto i : views::iota(1, N + 1)) { int dif = std::distance(S.begin() + i, std::lower_bound(S.begin() + i, S.end(), S[i - 1] + x)); if (dif > N) continue; if (S[dif + i] - S[i - 1] < x) continue; if (S[dif + i] - S[i - 1] > X) continue; debug(i, dif, x); return true; } return false; }; while (lo <= hi) { long long x = (lo + hi) / 2; if (check(x)) { lo = x + 1; ans = x; } else { hi = x - 1; } } print(ans); #ifdef LOCAL print("\nRunning Time:", chrono.elapsed(), "ms"); #endif }