#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; ll dp[5][100010]; ll s[5][100010]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, l; cin >> n >> l; int c[4]{}; rep(i, n) cin >> c[i]; dp[4][0] = 1; rrep(k, 4) { rep(i, l + 1) { dp[k][i] += dp[k+1][i]; if (i + c[k] + 1 <= l) dp[k][i+c[k]+1] -= dp[k+1][i]; } rep(i, l) dp[k][i+1] += dp[k][i]; rep(i, l+1) s[k][i+1] = s[k][i] + dp[k][i]; } // rep(k, 3) { // rep(i, 7) cout << dp[k][i] << ' '; // cout << endl; // } int q; cin >> q; while(q--) { ll K; cin >> K; K--; if (K >= dp[0][l]) { cout << -1 << '\n'; continue; } int a[4]{}; int rest = l; rep(k, 4) { int mn = rest; for(int t = k + 1; t < 4; t++) mn -= c[t]; chmax(mn, 0); int mx = min(rest, c[k]); int l = mn - 1, r = mx; while(r - l > 1) { int mid = (l + r) / 2; // [rest-mx, rest-mid) ll skip = s[k+1][rest - mid] - s[k+1][rest - mx]; if (skip <= K) { r = mid; } else { l = mid; } } a[k] = r; ll skip = s[k+1][rest - r] - s[k+1][rest - mx]; K -= skip; rest -= r; } // cout << K << endl; // rep(i, 3) cout << a[i] << ' '; // cout << endl; assert(K == 0); rep(i, n) cout << a[i] << " \n"[i + 1 == n]; } }