import sequtils,strutils,math type item = tuple[c : int, v : int] var T = stdin.readline.parseInt N = stdin.readline.parseInt C = stdin.readline.split.map(parseInt) V = stdin.readline.split.map(parseInt) dp : array[16,array[10001,int]] c,v,v2 : int for n in 0.. 1: v2 = v2 div 2 v += v2 c += C[n] items.add((c,v)) for i in 0..T: dp[n + 1][i] = max(dp[n + 1][i],dp[n][i]) for t in items: if t.c + i <= T: dp[n + 1][i + t.c] = max(dp[n + 1][i + t.c], dp[n][i] + t.v) echo dp[N][T]