public class No_216 { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int n = sc.nextInt(); int[] score = new int[n]; int[] answeredNum = new int[n]; for (int i = 0; i < n; i++) { score[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { answeredNum[i] = sc.nextInt(); } int kScore = 0; int[] personScore = new int[n]; for (int i = 0; i < n; i++) { if (answeredNum[i] == 0) { kScore += score[i]; } else { personScore[answeredNum[i]] += score[i]; } } java.util.Arrays.sort(personScore); int maxScore = personScore[n - 1]; String ans = kScore >= maxScore ? "YES" : "NO"; System.out.println(ans); } }