#include<cstdio>
#include<algorithm>
using namespace std;
#define N 150
int n,f[N],ans;
struct node{
int fen,t;
bool operator < (const node &b)const{return t<b.t;}
}a[N];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i].t);
for(int i=1;i<=n;i++) scanf("%d",&a[i].fen);
stable_sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
for(int j=a[i].t;j;j--)
f[j]=max(f[j],f[j-1]+a[i].fen);
for(int i=1;i<=n;i++) ans=max(ans,f[i]);
printf("%d",ans);
return 0;
}