#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b>N>>L; vector c(N); for(int i=0;i>c[i]; dp[N][0]=1; for(int i=N;i>=1;i--){ for(int j=0;j<=L;j++){ dp[i-1][j]+=dp[i][j]; dp[i-1][j+c[i-1]+1]-=dp[i][j]; } for(int j=1;j<=L;j++) dp[i-1][j]+=dp[i-1][j-1]; } for(int t=0;t<=N;t++){ for(int j=1;j<=L;j++) dp[t][j]+=dp[t][j-1]; } int Q;cin>>Q; while(Q--){ ll x;cin>>x;x--; if(x>=(dp[0][L]-dp[0][L-1])){ cout<<-1<<"\n"; continue; } vector ans; int rem=L; for(int t=0;t1){ int mid=(left+right)/2; ll xx=dp[t+1][rem-mid]; if(rem-min(c[t],rem)>0) xx-=dp[t+1][rem-min(c[t],rem)-1]; if(xx>x){ left=mid; }else{ right=mid; } } ans.push_back(left); ll xx=dp[t+1][rem-right]; if(rem-min(c[t],rem)>0) xx-=dp[t+1][rem-min(c[t],rem)-1]; x-=xx; rem-=left; } ans.push_back(rem); for(int x:ans) cout<