using System; using System.Globalization; using System.Linq; class Program { public static void Main(string[] args) { var t = int.Parse(Console.ReadLine()); var n = int.Parse(Console.ReadLine()); var ci = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var vi = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] dp = new int[t + 1]; int[,] counts = new int[t+ 1, n]; for (int dt = 1; dt <= t; dt++) { int next = -1; int maxIndex = -1; for (int k = 0; k < n; k++) { var current = 0; if (dt - ci[k] >= 0) { current = dp[dt - ci[k]] + (int) (vi[k]*Math.Pow(1/2d, counts[dt - ci[k], k])); } else { continue; } if(next < current) { next = current; maxIndex = k; } } if (next == - 1) { dp[dt] = dp[dt-1]; for (int i = 0; i < n; i++) { if (dt - ci[i] >= 0) { counts[dt, i] = counts[dt - ci[i], i]; } else { counts[dt, i] = 0; } } continue; } dp[dt] = next; for (int i = 0; i < n; i++) { if (dt - ci[i] >= 0) { counts[dt, i] = counts[dt - ci[i], i]; } else { counts[dt, i] = 0; } } counts[dt, maxIndex]++; } Console.WriteLine(dp[t].ToString(CultureInfo.InvariantCulture)); } }