#pragma region Macros #if defined(ONLINE_JUDGE) #include #endif #if defined(LOCAL) || defined(_DEBUG) #include "template.hpp" #else #include #include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define O(...) #define OP(...) #define START() #define STOP() #define MEMORY() #define massert(x, msec) if(!(x)) {\ while(msec > chrono::duration_cast(chrono::system_clock::now() - _MY_START_TIME).count()); \ cerr << "assert [" << __FUNCTION__ << ":" << to_string(__LINE__) << "] : " << string(#x) << el; exit(1);\ } /******************************************* マクロ等 **************************************************/ #define REP(i, n) for(ll i=0, i##_len=(n); i=0; --i) #define FOR(i, n, m) for(ll i=(m), i##_len=(n); i __FREP_CNT_ARRAY; #define FREP(i, n) ;__FREP_CNT_ARRAY.push_back(n); REP(i, n) { #define FREPR(i, n) ;__FREP_CNT_ARRAY.push_back((n)+1); REPR(i, n) { #define FFOR(i, n, m) ;__FREP_CNT_ARRAY.push_back((n)-(m)); FOR(i, n, m) { #define FEACH(a, as) ;__FREP_CNT_ARRAY.push_back((as).size()); EACH(a, as) { #define THEN __FREP_CNT_ARRAY.back()--;} if(bool frep_tmp = !__FREP_CNT_ARRAY.back(); __FREP_CNT_ARRAY.pop_back(), frep_tmp) #define DPINIT(name) name; bool __SEEN_##name; #define DP(name) name;if(__SEEN_##name)return name;__SEEN_##name=true; templatebool chmax(T &a, const U &b) { if (a<(T)b) { a=(T)b; return 1; } return 0; } templatebool chmin(T &a, const U &b) { if (b<(T)a) { a=(T)b; return 1; } return 0; } #define cmp3(a, x, b) ((a) <= (x) && (x) < (b)) #define vec vector #define umap unordered_map #define uset unordered_set using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair; using Tup = tuple; using vl = vec; using vvl = vec; #define fi first #define se second #define pb push_back #define el '\n' constexpr ll INF = numeric_limits::max()/4-1; /******************************************* 入力 **************************************************/ template istream &operator>>(istream &stream, vec& o){REP(i, o.size())stream >> o[i];return stream;} template istream &operator>>(istream &stream, pair& o){cin >> o.fi >> o.se; return stream;} namespace myinput { void input() {} template void input(T&& o, Ts&&... args){cin >> o;input(forward(args)...);} void assign_vl(size_t) {}; template void assign_vl(size_t siz, T&& o, Ts&&... args){o.resize(siz);assign_vl(siz, forward(args)...);} void input_horizon_sub(size_t) {}; template void input_horizon_sub(size_t index, T&& o, Ts&&... args) {cin>>o[index];input_horizon_sub(index, forward(args)...);} template void input_horizon(size_t siz, Ts&&... args){REP(i, siz) input_horizon_sub(i, forward(args)...);} } #define _I(T, ...) ;myinput::input(__VA_ARGS__); #define I(T, ...) ;T __VA_ARGS__;_I(T, __VA_ARGS__); #define _Iv(T, siz, ...) ;myinput::assign_vl(siz, __VA_ARGS__);myinput::input(__VA_ARGS__); #define Iv(T, siz, ...) ;vec __VA_ARGS__;_Iv(T, siz, __VA_ARGS__); #define _Ih(T, siz, ...) ;myinput::assign_vl(siz, __VA_ARGS__);myinput::input_horizon(siz, __VA_ARGS__); #define Ih(T, siz, ...) ;vec __VA_ARGS__;_Ih(T, siz, __VA_ARGS__); chrono::system_clock::time_point _MY_START_TIME; /******************************************* 出力 **************************************************/ namespace __PrintHelper { template void printValue(std::ostream& os, const T& value) { os << value; } template void printValue(std::ostream& os, const std::pair& value) { os << value.first << Separator << value.second; } template void printTuple(std::ostream& os, const std::tuple& value, std::index_sequence) { ((os << (Is == 0 ? "" : string(1, Separator)) << std::get(value)), ...); } template void printValue(std::ostream& os, const std::tuple& value) { printTuple(os, value, std::index_sequence_for{}); } template void printValue(std::ostream& os, const std::vector& value) { for (std::size_t i = 0; i < value.size(); ++i) os << (i == 0 ? "" : string(1, Separator)) << value[i]; } }; template void OO(const Arg &x, const Args&... args) { __PrintHelper::printValue(cout, x); if constexpr (sizeof...(args) > 0) { cout << Separator; OO(args...); } else { cout << el; } } template void YN(bool x, T y = "Yes", U n = "No") { if(x) cout << y << el; else cout << n << el; } /******************************************* 配列操作 **************************************************/ namespace __ArrayHelper { template auto flatten(const std::tuple& t); template auto flattenHelper(const T& t, std::index_sequence) { return std::make_tuple(std::get(t)...); } template auto flatten(const std::pair& p) { return flatten(std::make_tuple(p.first, p.second)); } template auto flatten(const T& value) { return std::make_tuple(value); } template auto flattenTupleHelper(const std::tuple& t, std::index_sequence) { return std::tuple_cat(flatten(std::get(t))...); } template auto flatten(const std::tuple& t) { return flattenTupleHelper(t, std::index_sequence_for{}); } template auto __flatten(const Container& container) { using ValueType = typename Container::value_type; using ResultType = decltype(__ArrayHelper::flatten(std::declval())); std::vector result; for (const auto& item : container) { result.emplace_back(__ArrayHelper::flatten(item)); } return result; } template auto __enumrate(const vec &v) { vec> ret(v.size()); REP(i, v.size()) ret[i] = {i, v[i]}; return ret; } } constexpr auto flatten = [](auto&& x) { return __ArrayHelper::__flatten(x); }; constexpr auto enumrate = [](auto&& x) { return __ArrayHelper::__enumrate(x); }; template auto zip(const Args&... args) { size_t minSize = std::min({args.size()...}); std::vector> result; for (size_t i = 0; i < minSize; ++i) { result.emplace_back(std::make_tuple(args[i]...)); } return result; } template Arg compose(Arg arg) { return arg; } template auto compose(Arg arg, Func func) { return func(arg); } template auto compose(Arg arg, Func func, Funcs... funcs) { return compose(compose(arg, func), funcs...); } /******************************************* Main **************************************************/ #endif #pragma endregion using Point = complex; void Main(); int main(){ _MY_START_TIME = std::chrono::system_clock::now(); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); std::cerr << std::fixed << std::setprecision(15); Main(); MEMORY(); return 0; } struct LS { queue q; ll value = 0; ll sum = 0; void push(ll x) { q.push(x); value += x * q.size(); sum += x; } void pop() { auto x = q.front(); q.pop(); value -= sum; sum -= x; } }; ll rec(ll h, vl &as, vl &bs) { LS ls; queue xs; ll sum = 0, mx = 0; REP(i, as.size()) { ls.push(bs[i]); xs.push(as[i]); sum += as[i]; while(ls.value > h) { ls.pop(); sum -= xs.front(); xs.pop(); } chmax(mx, sum); } return mx; } void Main() { I(ll, n, h); Iv(ll, n, as, bs); vvl aas(1), bbs(1); REP(i, n) { if(bs[i] > h) { aas.pb(vl()); bbs.pb(vl()); continue; } aas.back().pb(as[i]); bbs.back().pb(bs[i]); } ll mx = 0; O(aas, bbs); REP(i, aas.size()) { chmax(mx, rec(h, aas[i], bbs[i])); } OO(mx); }