import math import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) n = I() a = LI() b = LI() s = [0]*(n+1) for i in range(n): s[b[i]] += a[i] if s[0] == max(s): print("YES") else: print("NO")