n = gets.to_i as = gets.split.map(&:to_i) bs = gets.split.map(&:to_i) ttt = Hash.new(0) ka = 0 (0...n).each do |i| if bs[i] == 0 ka += as[i] else ttt[bs[i]] += as[i] end end if ka >= ttt.max_by { |k,v| v }[1] puts 'YES' else puts 'NO' end