## https://yukicoder.me/problems/no/2025 def main(): N, L = map(int, input().split()) C = list(map(int, input().split())) Q = int(input()) K = [] for _ in range(Q): K.append((int(input()))) # dpを使って利用する個数を計算 dp = [[0] * (L + 1) for _ in range(N)] dp[0][0] = 1 cum_dp = [[0] * (L + 1) for _ in range(N)] cum_ = 0 for i in range(L + 1): cum_ += dp[0][i] cum_dp[0][i] = cum_ for i in range(N - 1): c = C[-i-1] for j in range(L + 1): if j - c - 1 >= 0: dp[i + 1][j] = cum_dp[i][j] - cum_dp[i][j - c - 1] else: dp[i + 1][j] = cum_dp[i][j] cum_ = 0 for j in range(L + 1): cum_ += dp[i + 1][j] cum_dp[i + 1][j] = cum_ # k_iごとに求めていく for k in K: rest_l = L answer = [] k0 = k for j in range(N - 1): c = C[j] def fn(value): l = max(rest_l - c, 0) if l == 0: return cum_dp[-j - 1][value] else: return cum_dp[-j - 1][value] - cum_dp[-j - 1][l - 1] if fn(rest_l) < k0: answer = -1 break low = max(rest_l - c, 0) if fn(low) >= k0: v = low else: high = rest_l while high - low > 1: mid = (high + low) // 2 if fn(mid) < k0: low = mid else: high = mid if fn(high) < k0: v = high + 1 else: v = low + 1 used_c1 = rest_l - v answer.append(used_c1) if v > max(rest_l - c, 0): k0 = k0 - fn(v - 1) rest_l = v if answer == -1: print(answer) else: sum_c = sum(answer) x = L - sum_c answer.append(x) print(" ".join(map(str, answer))) if __name__ == "__main__": main()