#include //#include using namespace std; //using namespace atcoder; using ll = long long; //using mint = modint998244353; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); /* dp(i, j) = 後ろから見てi番目までで和をjにできるか? Pの小さい順に先頭の文字として採用できるかどうかを見る。 P_iが先頭の数字として採用できるかどうかは dp(i+1, M-B_i) = 1かどうかで判定できる。 次にP_jを先頭の文字として判定できるかどうかは MからB_iを引いておくと i> N >> M; vector p(N+1), a(N+1), q(N+1); for (int i=1; i<=N; i++) cin >> a[i]; for (int i=1; i<=N; i++){ cin >> p[i]; q[p[i]] = i; } vector dp(N+2, vector(M+1)); dp[N+1][0] = 1; for (int i=N; i>=1; i--){ for (int j=0; j<=M; j++){ if (dp[i+1][j] == 1 && j+a[i]<=M) dp[i][j+a[i]] = 1; if (dp[i+1][j] == 1) dp[i][j] = 1; } } if (!dp[1][M]){ cout << -1 << endl; return 0; } vector ans; int now=0; while(M){ for (int i=1; i<=N; i++){ int rev = q[i]; if (now >= rev) continue; if (M-a[rev] >= 0 && dp[rev+1][M-a[rev]]){ now = rev; M -= a[rev]; ans.push_back(rev); break; } } } cout << ans.size() << endl; for (auto x : ans) cout << x << " "; cout << endl; return 0; }