#include #define rep(i, p, n) for (ll i = p; i < (ll)(n); i++) #define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--) using namespace std; using ll = long long; using ld = long double; const double pi = 3.141592653589793; const long long inf = 2 * 1e9; const long long linf = 4 * 1e18; const ll mod1 = 1000000007; const ll mod2 = 998244353; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // atcoder #include using namespace atcoder; using mint1 = modint1000000007; using mint2 = modint998244353; vector> base = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int main() { ////////////////// ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ////////////////// ll N, M, K; cin >> N >> M >> K; vector A(N); rep(i, 0, N) { cin >> A.at(i); } vector> dp(M + 1, vector((1 << N), linf)); rep(i, 0, (1 << N)) { dp.at(0).at(i) = 0; rep(j, 0, N) { if (!(i & (1 << j))) { dp.at(0).at(i) += A.at(j); } } } ll now, temp; vector> pl(1 << N); vector>> mae(N, vector>((1 << N))); rep(i, 0, (1 << N)) { for (ll c = i; c; c = (c - 1) & i) { pl.at(i).push_back((__builtin_popcount(i) - __builtin_popcount(c)) * K); } pl.at(i).push_back((__builtin_popcount(i) - __builtin_popcount(0)) * K); } rep(p, 0, N) { rep(i, 0, (1<> N); now |= (c / 2); now |= (c % 2) * (1 << (N - 1)); now -= (now & (1 << p)); mae.at(p).at(i).push_back(now); } now = i; now -= (now & (1 << p)); mae.at(p).at(i).push_back(now); } } rep(p, 0, M) { ll B; cin >> B; B--; rep(i, 0, (1 << N)) { ll F = 0; for (ll c = i; c; c = (c - 1) & i) { chmin(dp.at(p + 1).at(mae.at(B).at(i).at(F)), dp.at(p).at(i)+pl.at(i).at(F)); F++; } chmin(dp.at(p + 1).at(mae.at(B).at(i).at(F)), dp.at(p).at(i)+pl.at(i).at(F)); } } rep(i, 0, M) { cout << dp.at(i + 1).at(0) << endl; } }