import Data.List main = getLine >> getLine >>= main' . map read . words where main' xs = getLine >>= putStrLn . solve . zip xs . map read . words solve :: [(Int, Int)] -> String solve xs | acc < mnum = "NO" | otherwise = "YES" where (acc, mnum) = foldl ff (0, 0) xs ff :: (Int, Int) -> (Int, Int) -> (Int, Int) ff (acc, mnum) (x, y) | y == 0 = (acc + x, max mnum x) | otherwise = (acc, max mnum x)