import java.util.Arrays;
import java.util.Scanner;
public class _01Inventory {
static int n;
static int w;
static int[] weight;
static int[] value;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
w = scanner.nextInt();
weight = new int[n];
value = new int[n];
for (int i = 0; i < n; i++) {
weight[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
value[i] = scanner.nextInt();
}
System.out.println(dfs(0, w));
dp = new int[n + 1][w + 1];
System.out.println(memoRecursion(0, w));
dp();
}
public static int dfs(int k, int n) {
if (k == _01Inventory.n) return 0;
if (n <= 0) return 0;
int r1 = dfs(k + 1, n);
if (weight[k] <= n) {
int r2 = value[k] + dfs(k + 1, n - weight[k]);
return Math.max(r1, r2);
} else {
return r1;
}
}
static int[][] dp;
public static int memoRecursion(int k, int ww) {
if (k == n) return 0;
if (ww <= 0) return 0;
if (dp[k][ww] != 0) {
return dp[k][ww];
}
int ans1 = memoRecursion(k + 1, ww);
if (ww >= weight[k]) {
ans1 = Math.max(ans1, value[k] + memoRecursion(k + 1, ww - weight[k]));
}
dp[k][ww] = ans1;
return ans1;
}
public static void dp() {
int[][] dp = new int[n][w + 1];
for (int j = 1; j < w + 1; j++) {
if (weight[0] <= j) {
dp[0][j] = value[0];
}
}
for (int i = 1; i < n; i++) {
for (int j = 1; j < w + 1; j++) {
if (weight[i] <= j) {
dp[i][j] = Math.max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
for (int[] s : dp) {
System.out.println(Arrays.toString(s));
}
}
}