Problem:
Score: 400 points

Problem Statement

Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.

Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.

It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.

Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.

Can Kizahashi complete all the jobs in time? If he can, print Yes; if he cannot, print No.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
.
.
.
A_N B_N

Output

If Kizahashi can complete all the jobs in time, print Yes; if he cannot, print No.

Sample Input 1

5
2 4
1 9
1 8
4 9
3 12

Sample Output 1

Yes

He can complete all the jobs in time by, for example, doing them in the following order:

Do Job 2 from time 0 to 1.

Do Job 1 from time 1 to 3.

Do Job 4 from time 3 to 7.

Do Job 3 from time 7 to 8.

Do Job 5 from time 8 to 11.

Note that it is fine to complete Job 3 exactly at the deadline, time 8.

Sample Input 2

3
334 1000
334 1000
334 1000

Sample Output 2

No

He cannot complete all the jobs in time, no matter what order he does them in.

Sample Input 3

30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720

Sample Output 3

Yes

Solution in Rust (1.15.1) (judge verdict: Accepted)

fn main() {
    let n = read();
    let works: Vec<(i32,i32)> = {
        let mut works: Vec<(i32,i32)> = (0..n).map(|_| read_pair()).collect();
        works.sort_by(|&(_, x), &(_, y)| x.cmp(&y));
        works
    };

    let mut t = 0;
    for (a,b) in works {
        t += a;
        if t > b { println!("No"); return; }
    }
    println!("Yes");
}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}
fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T>{
    get_line().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_pair<T: std::str::FromStr + Copy>() -> (T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1])
}
fn read_triple<T: std::str::FromStr + Copy>() -> (T,T,T){
    let v:Vec<T> = read_vec(); (v[0], v[1], v[2])
}

const MOD: u64 = 1_000_000_007;

#[derive(Copy, Clone, PartialEq, Eq)]
struct F(u64);

impl F {
    pub fn new(n: i32) -> Self { F((MOD as i32 + n)as u64%MOD) }
    pub fn pow(self, mut exp: u32) -> Self {
        let mut base = self.0;
        let mut acc = 1;
        while exp > 1 {
            if (exp & 1) == 1 { acc *= base; acc %= MOD; }
            exp /= 2; base *= base; base %= MOD;
        }
        if exp == 1 { acc *= base;acc %= MOD; }
        F(acc)
    }
}
impl std::fmt::Display for F {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
use std::ops::*;
impl Mul for F {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {F((self.0 * rhs.0)%MOD)}
}
impl MulAssign for F {
    fn mul_assign(&mut self, rhs: Self) {*self = F((self.0 * rhs.0)%MOD)}
}
impl Add for F {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {F((self.0 + rhs.0)%MOD)}
}
impl AddAssign for F {
    fn add_assign(&mut self, rhs: Self) {*self = F((self.0 + rhs.0)%MOD)}
}
impl Neg for F {
    type Output = Self;
    fn neg(self) -> Self {if self.0==0 {F(0)} else {F(MOD - self.0)}}
}
impl Sub for F {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {F((MOD + self.0 - rhs.0)%MOD)}
}
impl SubAssign for F {
    fn sub_assign(&mut self, rhs: Self) {*self = F((MOD + self.0 - rhs.0)%MOD)}
}
impl Div for F {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {F(self.0 * rhs.pow(MOD as u32-2).0 %MOD)}
}
impl DivAssign for F {
    fn div_assign(&mut self, rhs: Self) { *self = F(self.0 * rhs.pow(MOD as u32 - 2).0 % MOD) }
}
impl std::iter::Sum<F> for F {
    fn sum<I: Iterator<Item=F>>(iter: I) -> F { iter.fold(F(0), |a,b| a + b) }
}
impl<'a> std::iter::Sum<&'a F> for F {
    fn sum<I: Iterator<Item=&'a F>>(iter: I) -> F { iter.fold(F(0), |a, b| a + *b) }
}
impl std::iter::Product for F {
    fn product<I: Iterator<Item=F>>(iter: I) -> F { iter.fold(F(1), |a, b| a * b) }
}
impl<'a> std::iter::Product<&'a F> for F {
    fn product<I: Iterator<Item=&'a F>>(iter: I) -> F { iter.fold(F(1), |a, b| a * *b) }
}