#include #define REP(i,n) for(int i=0; i<(n); i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector score(N); for( auto&& x : score ) { cin >>x; } vector no(N); for( auto&& x : no ) { cin >>x; } map mp; REP( i, N ) { mp[ no[i] ] += score[i]; } int MAX{INT_MIN}, LO{}; for( auto& x : mp ) { //left over if( x.first == 0 ) { LO += x.second; } else { //max score MAX = max( MAX, x. second ); } } cout << ( LO >= MAX ? "YES" : "NO" ) << endl; return 0; }