#include #include #include #include #include #include #define ll long long #define P pair #define lP pait using namespace std; int main() { int n,ma=0,k=0; cin>>n; vector a(n),b(n),c(n); for(int i=0;i>a[i]; } for(int i=0;i>b[i]; c[b[i]]+=a[i]; ma=max(ma,c[i]); if(b[i]==0) k+=a[i]; } if(k>=ma) cout<<"YES"<