let f (_, x) (_, y) = x-y
let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun a b -> a, b)) in
  Array.sort f a;
  a |> Array.fold_left (fun (msg, t) (a, b) ->
    if msg = "Yes" && t+a <= b then ("Yes", t+a) else ("No", -1)) ("Yes", 0)
  |> fst |> print_endline
