package net.ipipip0129.yukicoder.no216; import java.util.Arrays; import java.util.Scanner; import java.util.stream.Stream; // 課題 Stream API を使う public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int cnt = Integer.parseInt(scan.nextLine()); int[] point_list = Stream.of(scan.nextLine().split(" ")) .mapToInt(Integer::parseInt) .toArray(); int[] answers = Stream.of(scan.nextLine().split(" ")) .mapToInt(Integer::parseInt) .toArray(); int[] get_points = new int[Arrays.stream(answers).max().getAsInt() + 1]; for (int i = 0; i < point_list.length; i++) get_points[answers[i]] += point_list[i]; if (get_points[0] == Arrays.stream(get_points).max().getAsInt()) { System.out.println("Yes"); }else { System.out.println("No"); } } }