n = gets.to_i points = gets.split.map(&:to_i) solved = gets.chomp.split h = Hash.new solved.zip(points) do |solved, points| if h[solved].nil? h[solved] = points else h[solved] += points end end if h.sort.sort_by{|k,v| -v}[0][0] == "0" puts "YES" else puts "NO" end