N = gets.to_i
height = gets.split.map(&:to_i)
beauty = gets.split.map(&:to_i)

# dp = Array.new(N, 0)
# dp[0] = beauty[0]
dp = beauty.dup

1.upto(N-1) do |i|
  0.upto(i-1) do |j|
    if height[i] > height[j]
      dp[i] = dp[j] + beauty[i] if dp[i] < dp[j] + beauty[i]
    end
  end
end
# p dp
puts dp[N-1]