#include <iostream> #include <algorithm> #include <string> #include <vector> #include <map> #include <set> #include <stdio.h> #include <cstring> #include <queue> #include <stack> #include <functional> #include <math.h> #include <iomanip> using namespace std; #define Would #define you const int INF = 999999999; const int MOD = 1e9 + 7; const double pi = 3.141592653589793238; int n, k[105], l[105], score, others[105]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> k[i]; } for (int i = 0; i < n; ++i) { cin >> l[i]; if (!l[i]) { score += k[i]; } else { others[l[i] - 1] += k[i]; } } sort(others, others + n); reverse(others, others + n); string ans; if (score > others[0]) { ans = "YES"; } else { ans = "NO"; } cout << ans << endl; }