include
include
include
include
include
include
include
include
include
include
include
include
define rep(i,j,k) for(register int i=j;i<=k;i++)
define rrep(i,j,k) for(register int i=j;i>=k;i--)
define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
define iin(a) scanf("%d",&a)
define lin(a) scanf("%lld",&a)
define din(a) scanf("%lf",&a)
define s0(a) scanf("%s",a)
define s1(a) scanf("%s",a+1)
define print(a) printf("%lld",(ll)a)
define enter putchar('\n')
define blank putchar(' ')
define println(a) printf("%lld\n",(ll)a)
define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e6+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x10+ch-'0';ch=getchar();}
return xf;
}
int n,cost[maxn],weight[maxn];
ll dp[maxn][2];//支撑前i天的最小代价,j当天买瓜1不买0
int main(){
while(cin>>n){
rep(i,1,n) cost[i]=read();
rep(i,1,n) weight[i]=read();
dp[0][1]=dp[0][0]=0;
dp[1][0]=oo;dp[1][1]=cost[1];
rep(i,2,n){
dp[i][0]=dp[i][1]=oo;
rep(j,1,i-1) if(j+weight[j]-1>=i){
dp[i][0]=min(dp[i][0],dp[j][1]);
}
rep(j,1,i-1) if(j+weight[j]-1>=i){
dp[i][1]=min(dp[i][1],dp[j][1]+cost[i]);
}
}
println(min(dp[n][0],dp[n][1]));
}
return 0;
}