#include #include #include #include #include #include #include #include #include #include #include #include #include namespace lib { templatestruct modnum; templateconstexpr T pow(T base, std::size_t p) { if (p == 0) { return T(1); } else if (p == 1) { return base; } else if (p == 2) { return base*base; } else if (p % 2 == 0) { return pow(pow(base, p / 2), 2); } else { return pow(pow(base, p / 2), 2)*base; } } templateconstexpr auto inverse(modnum const&); templatestruct modnum { static constexpr auto mod = Mod; std::uint64_t val; modnum() = default; constexpr modnum(std::uint64_t v) :val(v%Mod) { } constexpr modnum& operator+=(modnum const& v) { val += v.val; val %= mod; return *this; } constexpr modnum& operator-=(modnum const& v) { val += mod - v.val; val %= mod; return *this; } constexpr modnum& operator*=(modnum const& v) { val *= v.val; val %= mod; return *this; } constexpr modnum& operator/=(modnum const& v) { return operator*=(inverse(v)); } }; templateconstexpr auto operator+(modnum lhs, modnumconst& rhs) { return lhs += rhs; } templateconstexpr auto operator-(modnum lhs, modnumconst& rhs) { return lhs -= rhs; } templateconstexpr auto operator*(modnum lhs, modnumconst& rhs) { return lhs *= rhs; } templateconstexpr auto operator/(modnum lhs, modnumconst& rhs) { return lhs /= rhs; } templateconstexpr auto inverse(modnumconst& base) { return pow(base, Mod - 2); } templateconstexpr auto clamp(T v) { return std::max(v, T()); } templatevoid sort(std::vector& vec) { std::sort(vec.begin(), vec.end()); } templateauto lower_bound(std::vectorconst& vec, T v) { return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v)); } templateauto upper_bound(std::vectorconst& vec, T v) { return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v)); } templatestruct dmod { std::uint64_t val; static std::uint64_t mod; dmod(std::uint64_t v = 0) :val(v%mod) { } dmod& operator+=(dmod const& rhs) { val += rhs.val; val %= mod; return *this; } dmod& operator-=(dmod const& rhs) { val += mod - rhs.val; val %= mod; return *this; } dmod& operator*=(dmod const& rhs) { val *= rhs.val; val %= mod; return *this; } }; templatedmod operator+(dmod lhs, dmod const& rhs) { return lhs += rhs; } templatedmod operator-(dmod lhs, dmod const& rhs) { return lhs -= rhs; } templatedmod operator*(dmod lhs, dmod const& rhs) { return lhs *= rhs; } templatestd::uint64_t dmod::mod; struct scope_exit { std::function func; scope_exit(std::function f) :func(f) { } ~scope_exit() { func(); } }; templateusing int_tag = std::integral_constant; } void Main(); int main() { std::cin.tie(nullptr); std::cin.sync_with_stdio(false); Main(); } std::uint64_t check(int index, int rest, std::vectorconst& costs) { static std::map> memo; if (rest == 0) { return 0; } if (memo.count(index) && memo[index].count(rest)) { return memo[index][rest]; } std::uint64_t min = std::numeric_limits::max(); for (int i = 0; i < index; ++i) { int j = i + 1; min = std::min((rest / j)*j*costs[i] + check(i, rest%j, costs), min); } return memo[index][rest] = min; } void Main() { std::uint64_t N, V; std::cin >> N >> V; std::vector cost(N); std::uint64_t sum; std::cin >> cost[0]; sum = cost[0]; for (int i = 1; i < N; ++i) { std::uint64_t v; std::cin >> v; sum += v; cost[i] = cost[i - 1] + v; } if (N >= V) { std::cout << sum << std::endl; return; } V -= N; std::uint64_t min = std::numeric_limits::max(); for (int i = 0; i < N; ++i) { min = std::min(min, (V / (i + 1))*(i + 1)*cost[i] + check(i, V % (i + 1), cost)); } std::cout << sum + min << std::endl; }