#include using namespace std; #define int long long typedef long long ll; typedef pairpint; typedef vectorvint; typedef vectorvpint; #define pb push_back #define mp make_pair #define fi first #define se second #define ln <void chmin(T &t,U f){if(t>f)t=f;} templatevoid chmax(T &t,U f){if(t>T>>N; rep(i,N)cin>>c[i]; rep(i,N)cin>>v[i]; fill_n(*dp,16*10010,INT_MIN); dp[0][0]=0; rep(i,N){ int s[10]={0}; int vv=v[i]; rep(j,9){ s[j+1]=s[j]+vv; vv>>=1; } rep(j,T+1){ rep(k,10){ if(j+c[i]*k>T)break; chmax(dp[i+1][j+c[i]*k],dp[i][j]+s[k]); } } } cout<<*max_element(dp[N],dp[N]+T+1)<