class Calc0216 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @as = args.shift.map(&:to_i) @bs = args.shift.map(&:to_i) end def calc scores = Array.new(101) { 0 } max_score = 0 @as.zip(@bs) do |a, b| if b == 0 max_score += a else scores[b] += a end end max_score >= scores.max end def run calc ? 'YES' : 'NO' end end puts Calc0216.new(STDIN.readlines).run if __FILE__ == $0