#include #include #include #include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using modint = atcoder::static_modint<998244353>; namespace RQ{ u64 op(u64 l, u64 r){ return l+r; } u64 e(){ return 0; } using RQ = atcoder::segtree; } int main(){ int N; cin >> N; int L; cin >> L; vector C(N); rep(i,N) cin >> C[i]; reverse(C.begin(), C.end()); vector> dp(N+1, vector(L+1,0)); dp[0][0] = 1; rep(d,N){ RQ::RQ rq(dp[d]); rep(i,L+1) dp[d+1][i] = rq.prod(max(0,i-C[d]), i+1); } vector> sumDp(N+1, vector(L+2,0)); rep(d,N+1) rep(i,L+1) sumDp[d][i+1] = sumDp[d][i] + dp[d][i]; rep(i,N+1){ //rep(j,L+2) cout << sumDp[i][j] << " "; //cout << endl; } int Q; cin >> Q; rep(qi, Q){ u64 k; cin >> k; if(dp[N][L] < k){ cout << "-1\n"; continue; } vector res(N); int len = L; for(int d=N-1; d>=0; d--){ //cout << "k = " << k << " , len = " << len << endl; u64 off = sumDp[d][max(0,len-C[d])]; int c = (lower_bound(sumDp[d].begin(), sumDp[d].end(), k+off) - sumDp[d].begin()) - 1; k = k - sumDp[d][c] + off; c = len - c; res[N-1-d] = c; len -= c; } rep(i,N){ if(i){ cout << ' '; } cout << res[i]; } cout << '\n'; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;