#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x>T>>N; FOR(i,N) cin>>C[i]; FOR(i,N) { cin>>V[i]; FOR(j,13) { VS[i][j+1]=VS[i][j]+V[i]; V[i]/=2; } FOR(j,T+1) FOR(x,11) if(j+x*C[i]<=T) DP[i+1][j+x*C[i]]=max(DP[i+1][j+x*C[i]],DP[i][j]+VS[i][x]); } cout << *max_element(DP[N],DP[N]+T+1) << endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }