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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

class Program{

    const long MOD =1000000007;

    static void Main(string[] args)
    {
        // ここにかく
        int n = ScanOneInt();
        int time = 0;
        bool can = true;
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; i++)
        {
            list.Add(ScanTuple());
        }
        list.Sort((a, b) => a.Item2.CompareTo(b.Item2));
        for (int i = 0; i < n; i++)
        {
            time += list[i].Item1;
            if(time > list[i].Item2)
            {
                can = false;
                break;
            }
        }

        Console.WriteLine(can ? "Yes": "No");
    }
    
    

    static T[] Ruiseki<T>(T[] array)
    {
        // i 番目の要素までの累積和 -> r[i]
        // 0 r[0] r[0] + r[1]... と続く
        T[] res = new T[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            if (i==0)
            {
                res[i] = array[i];
            }
            else
            {
                res[i] = (dynamic)res[i - 1] + (dynamic)array[i];
            }
        }
        return res;
    }

    static T[] RuisekiRev<T>(T[] array)
    {
        T[] res = new T[array.Length];
        for (int i = array.Length-1; i >= 0; i--)
        {
            if (i == array.Length-1)
            {
                res[i] = array[i];
            }
            else
            {
                res[i] = (dynamic)res[i + 1] + (dynamic)array[i];
            }
        }
        return res;
    }

    static int Nibutan(long[] array, long k)
    {
        int low = 0 ;
        int high = array.Length-1;
        int mid = high;

        while (low < high)
        {
            mid = (low + high) / 2;
            if(array[mid] >= k) // k以上の最小index.ココを変えるだけ
            {
                high = mid;
            }
            else
            {
                low = mid + 1;
            }
            mid = (low + high) / 2;
        }
        return mid;
    }   

    static int ScanOneInt()
    {
        return int.Parse(Console.ReadLine());
    }

    static long ScanOneLong()
    {
        return long.Parse(Console.ReadLine());
    }

    static string[] ScanStringArray(int lines)
    {
        string[] str = new string[lines];
        for (int i = 0; i < lines; i++)
        {
            str[i] = Console.ReadLine();
        }
        return str;
    }

    static int[] ScanIntArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] ar = new int[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = int.Parse(str[i]);
        }
        return ar;
    }

    static Tuple<int,int> ScanTuple()
    {
        int[] tmp = ScanIntArray(2);
        return new Tuple<int, int>(tmp[0], tmp[1]);
    }

    static long[] ScanLongArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] ar = new long[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = long.Parse(str[i]);
        }
        return ar;
    }

    static double[] ScanDoubleArray(int t)
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] ar = new double[t];
        for (int i = 0; i < t; i++)
        {
            ar[i] = double.Parse(str[i]);
        }
        return ar;
    }

    static int[,] ScanIntSquareArray(int h, int w)
    {
        int[,] resAr = new int[h, w];
        for (int i = 0; i < h; i++)
        {
            int[] ar = ScanIntArray(w);
            for (int j = 0; j < w; j++)
            {
                resAr[i, j] = ar[j];
            }
        }
        return resAr;
    }

    static int[,] CombModMake()
    {
        int[,] res = new int[2005, 2005];
        for (int i = 0; i < 2005; i++)
        {
            for (int j = 0; j < 2005; j++)
            {
                if (i == 0 || i < j)
                {
                    res[i, j] = 0;
                }
                else if (j == 0 || i == j)
                {
                    res[i, j] = 1;
                }
                else
                {
                    res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD;
                }
            }
        }
        return res;
    }

    // int, long両方で出来るGCDを作った
    static T GCD<T>(T a, T b)
    {
        if((dynamic)a % (dynamic)b == 0)
        {
            return b;
        }
        else
        {
            return GCD((dynamic)b, (dynamic)a % (dynamic)b);
        }
    }

}


public class Pair<T,U>: IComparable where T : IComparable<T> where U: IComparable<U>
{
    public T Item1;
    public U Item2;

    public int  CompareTo(object obj)
    {
        Pair<T,U> pair = (Pair<T, U>)obj;
        return Item1.CompareTo(pair.Item1);
    }
    public Pair(T t, U u)
    {
        Item1 = t;
        Item2 = u;
    }

}

// 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN)
// ToArray()で配列化
public class PriorityQueue<T> where T : IComparable
{
    private IComparer<T> _comparer = null;
    private int _type = 0;
    private T[] _heap;
    private int _sz = 0;
    private int _count = 0;

    /// <summary>
    /// Priority Queue with custom comparer
    /// </summary>
    public PriorityQueue(int maxSize, IComparer<T> comparer)
    {
        _heap = new T[maxSize];
        _comparer = comparer;
    }

    /*
     -> Item: _heap(ヒープを持つ.sizeはmaxSize)
     -> Item: _type -> 0:asc(昇順), 1:desc(降順)
     */
    public PriorityQueue(int maxSize, int type = 0)
    {
        _heap = new T[maxSize];
        _type = type;
    }

    private int Compare(T x, T y)
    {
        if (_comparer != null) return _comparer.Compare(x, y);
        return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
        // typeが0なら昇順, 1なら降順にソートするCompare
    }

    public void Push(T x)
    {
        _count++;

        //node number
        var i = _sz++;

        while (i > 0)
        {
            //parent node number
            var p = (i - 1) / 2;
            if (Compare(_heap[p], x) <= 0) break;
            _heap[i] = _heap[p];
            i = p;
        }

        _heap[i] = x;
    }

    public T Pop()
    {
        _count--;

        T ret = _heap[0];
        T x = _heap[--_sz];

        int i = 0;
        while (i * 2 + 1 < _sz)
        {
            //children
            int a = i * 2 + 1;
            int b = i * 2 + 2;

            if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b;

            if (Compare(_heap[a], x) >= 0) break;

            _heap[i] = _heap[a];
            i = a;
        }

        _heap[i] = x;

        return ret;
    }

    public int Count()  // O(1)
    {
        return _count;
    }

    public T Peek() // O(1)
    {
        return _heap[0];
    }

    public bool Contains(T x)   // O(N)なので注意
    {
        for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true;
        return false;
    }

    public void Clear()
    {
        while (Count() > 0) Pop();
    }

    public IEnumerator<T> GetEnumerator() // なにこれ
    {
        var ret = new List<T>();

        while (Count() > 0)
        {
            ret.Add(Pop());
        }

        foreach (var r in ret)
        {
            Push(r);
            yield return r;
        }
    }

    public T[] ToArray()
    {
        T[] array = new T[_sz];
        int i = 0;

        foreach (var r in this)
        {
            array[i++] = r;
        }

        return array;
    }
}

public class GenericOperation<T>
{
    public GenericOperation()
    {
        var availableT = new Type[]
        {
            typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(long), typeof(ulong), typeof(byte),
            typeof(decimal), typeof(double)
        };
        if (!availableT.Contains(typeof(T)))
        {
            throw new NotSupportedException();
        }
        var p1 = Expression.Parameter(typeof(T));
        var p2 = Expression.Parameter(typeof(T));
        Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2).Compile();
        Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2).Compile();
        Multiply = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2).Compile();
        Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2).Compile();
        Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2).Compile();
        Equal = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2).Compile();
        GreaterThan = Expression.Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2).Compile();
        GreaterThanOrEqual = Expression.Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2), p1, p2).Compile();
        LessThan = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2).Compile();
        LessThanOrEqual = Expression.Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1, p2).Compile();
    }

    public Func<T, T, T> Add { get; private set; }
    public Func<T, T, T> Subtract { get; private set; }
    public Func<T, T, T> Multiply { get; private set; }
    public Func<T, T, T> Divide { get; private set; }
    public Func<T, T, T> Modulo { get; private set; }
    public Func<T, T, bool> Equal { get; private set; }
    public Func<T, T, bool> GreaterThan { get; private set; }
    public Func<T, T, bool> GreaterThanOrEqual { get; private set; }
    public Func<T, T, bool> LessThan { get; private set; }
    public Func<T, T, bool> LessThanOrEqual { get; private set; }
}

class Segtree<T>
{
    int n;
    T[] tree;
    Func<T, T, T> f;
    T exnum;
    public Segtree(int m, Func<T, T, T> f, T ex)
    {
        this.f = f;
        exnum = ex;
        n = 1;
        while (n < m) n <<= 1;  // resize calc
        tree = new T[(n << 1) - 1]; // resize
        for (int i = 0; i < tree.Length; i++) tree[i] = ex; // init
    }
    public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex)
    {
        for (int i = 0; i < m; ++i) tree[i + n - 1] = ini;
        All_update();
    }
    public void Assign_without_update(int j, T x)
    {
        tree[j + n - 1] = x;
    }
    public void Update(int j, T x)
    {
        int i = j + n - 1;
        tree[i] = x;
        while (i > 0)
        {
            i = (i - 1) >> 1;
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
        }
    }
    public void All_update()
    {
        for (int i = n - 2; i >= 0; i--)
            tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]);
    }
    public T Look(int i) { return tree[i + n - 1]; }

    // [s, t)
    public T Run(int s, int t) { return Query(s, t, 0, 0, n); }
    T Query(int s, int t, int k, int l, int r)
    {
        if (r <= s || t <= l) return exnum;
        if (s <= l && r <= t) return tree[k];

        return f(Query(s, t, (k << 1) + 1, l, (l + r) >> 1), Query(s, t, (k + 1) << 1, (l + r) >> 1, r));
    }
}