#include #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = std::int64_t; using P = std::tuple; constexpr ll INF = 1001001001001001001; template struct Matrix{ std::vector> row; Matrix() = default; Matrix(int n, int m) : row(n, std::vector(m, INF)) {} std::vector& operator[](int r){ return row[r]; } Matrix& operator*=(Matrix& rhs){ int n = row.size(), m = rhs.row.size(), l = rhs[0].size(); Matrix product(n, l); for(int i=0;i operator*(Matrix lhs, Matrix& rhs){ lhs *= rhs; return lhs; } static Matrix identity(int n){ Matrix I(n, n); for(int i=0;i Matrix mat_expt(Matrix a, std::int64_t n){ Matrix power = std::move(Matrix::identity(a.row.size())); while(n > 0){ if(n & 1){power *= a;} a *= a; n >>= 1; } return power; } int N, V; ll C[110], D[110]; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N >> V; for(int i=0;i> C[i]; } D[0] = C[0]; for(int i=1;i A(N, N), v(N, 1); for(int i=0;i+1 w = std::move(mat_expt(A, V) * v); minCost += w[0][0]; std::cout << minCost << std::endl; }