using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var p = NList; var (n, m, w) = (p[0], p[1], p[2]); var a = NList; var b = NList; var c = NList; var d = NList; var bitmax = 1 << n + m; var dp = new long[bitmax][]; for (var i = 0; i < dp.Length; ++i) dp[i] = Enumerable.Repeat(long.MinValue / 2, w + 1).ToArray(); dp[0][0] = 0; for (var i = 0; i < dp.Length; ++i) { for (var j = 0; j < n + m; ++j) { var next = i | (1 << j); if (next == i) continue; for (var k = 0; k <= w; ++k) { if (j < n) { if (k + a[j] > w) continue; dp[next][k + a[j]] = Math.Max(dp[next][k + a[j]], dp[i][k] + b[j]); } else { if (k - c[j - n] < 0) continue; dp[next][k - c[j - n]] = Math.Max(dp[next][k - c[j - n]], dp[i][k] - d[j - n]); } } } } var ans = 0L; foreach (var dl in dp) foreach (var di in dl) ans = Math.Max(ans, di); WriteLine(ans); } }