#include using namespace std; using Line = bitset<2001>; int main() { int N, M; cin >> N >> M; vector A(N); for (int &a : A) cin >> a; vector P(N); for (int &p : P) cin >> p; vector Pinv(N); for (int i = 0; i < N; ++i) Pinv[P[i] - 1] = i; int last_idx = -1; vector ans; for (int i = 0; i < N; ++i) { int p_idx = Pinv[i]; // cout << p_idx << " " << i << " " << M << " " << A[p_idx] << endl; if (p_idx <= last_idx) continue; Line z = 0; z[0] = 1; for (int j = p_idx + 1; j < N; ++j) z |= z << A[j]; // cout << z[1] << " " << z[0] << endl; if (M >= A[p_idx] && z[M - A[p_idx]]) { ans.push_back(p_idx + 1); last_idx = p_idx; M -= A[p_idx]; i = -1; } } if (M != 0) { cout << -1 << endl; assert(ans.empty()); } else { assert(!ans.empty()); cout << ans.size() << endl; for (int x : ans) cout << x << " "; cout << endl; } }