/* -*- coding: utf-8 -*- * * 216.cc: No.216 FAC - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ /* global variables */ int as[MAX_N], scs[MAX_N]; /* subroutines */ /* main */ int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> as[i]; int mysc = 0, maxsc = 0; for (int i = 0; i < n; i++) { int bi; cin >> bi; bi--; if (bi < 0) mysc += as[i]; else { scs[bi] += as[i]; if (maxsc < scs[bi]) maxsc = scs[bi]; } } cout << (mysc >= maxsc ? "YES" : "NO") << endl; return 0; }