using System; using System.Linq; class Program { static void Main(string[] args) { // 入力 var N = int.Parse(Console.ReadLine()); var points = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var solvers = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); if (solvers.Contains(0)) { var results = solvers.Zip(points, (number, score) => new { N = number, S = score }).ToList(); var r2 = results.GroupBy(x => new { x.N }).Select(x => new { N = x.Key.N, S = x.Sum(d => d.S) }).ToList(); var myScore = r2.Where(x => x.N == 0).Max(x => x.S); var max = r2.Max(x => x.S); if (myScore >= max) Console.WriteLine("YES"); else Console.WriteLine("NO"); return; } Console.WriteLine("NO"); } }