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.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Collections;

namespace Atcoder
{
    class Pair:IComparable
    {
        public int a;
        public int b;
        public Pair(int A,int B)
        {
            a = A;b = B;
        }
        public int CompareTo(object obj)
        {
            Pair two = (Pair)obj;
            return b.CompareTo(two.b);
        }
    }
    class Program
    {

        static void Main(string[] args)
        {

            StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
            int n = scan.Integer();
            Pair[] ab = new Pair[n];
            for (int i = 0; i < n; i++)
            {
                ab[i] = new Pair(scan.Integer(), scan.Integer());
            }
            Array.Sort(ab);
            int time = 0;
            for (int i = 0; i < n; i++)
            {
                time += ab[i].a;
                if (time > ab[i].b) { Console.WriteLine("No"); return; }
            }
            Console.WriteLine("Yes");
        }
        static long Syakutori(int[]a,long k)//しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上
        {
            long sum = 0;
            int right = 0;
            long ans = 0;
            for (int left = 0; left < a.Length; left++)
            {
                while (right < a.Length&&sum<k)
                {
                    sum += a[right];right++;
                
                }
                if (k <= sum) { ans += a.Length - right + 1; }
                if (left == right) { right++; }
                else { sum -= a[left]; }
            }
            return ans;
        }
       static int[] zalgo(String s)
        {
            int n = s.Length;
            int[] ret = new int[n];
            ret[0] = n;
            int i = 1, j = 0;
            while (i < n)
            {
                while (i + j < n && s[j] == s[i + j])
                    ++j;
                ret[i] = j;
                if (j == 0)
                {
                    ++i;
                    continue;
                }
                int k = 1;
                while (i + k < n && k + ret[k] < j)
                {
                    ret[i + k] = ret[k];
                    ++k;
                }
                i += k;
                j -= k;
            }
            return ret;
        }
        static int gcd(int a,int b)
        {
            if (a % b == 0) { return b; }
            return gcd(b, a % b);
        }
        static int[]yousogotoplus(int[]a,int[]b)
        {
            int[] c = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                c[i] = a[i] + b[i];
            }
            return c;
        }
        static int[] yousogotoplus(int[] a, int[,] b, int l)
        {
            int[] c = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                c[i] = a[i] + b[l,i];
            }
            return c;
        }
        
        static int[] yousogotoplus(int[,] a,int l)
        {
            int[] c = new int[a.GetLength(1)];
            for (int i = 0; i < a.GetLength(1); i++)
            {
                c[i] = a[l, i];
            }
            return c;
        }
        static long solve(int mae,int ushiro,long[,]dp,int[]a,bool taro)
        {
            if (dp[mae, ushiro] > long.MinValue)
            {
                return dp[mae, ushiro];
            }
            if (ushiro - mae == 1)
            {
                if (taro) { dp[mae, ushiro] = a[mae]; return dp[mae, ushiro]; }
                else { dp[mae, ushiro] = -a[mae]; return dp[mae, ushiro]; }
            }

            if(taro)
            {
                long max = Math.Max(a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
                    a[ushiro-1] + solve(mae, ushiro - 1, dp, a, !taro));
                dp[mae, ushiro] = max;
                return dp[mae, ushiro];
                
            }
            else
            {
                long min= Math.Min(-a[mae] + solve(mae + 1, ushiro, dp, a, !taro),
                    -a[ushiro-1] + solve(mae, ushiro - 1, dp, a, !taro));
                dp[mae, ushiro] = min;
                return dp[mae, ushiro];
            }
            
        }

        static int nibutan(int med,int[]a)//med以上が何個あるか
        {
            int mae = 0;
            int ato = a.Length;
            while (true)
            {
                if (ato - mae <= 1) {
                    return mae; }
                int mid = (mae + ato) / 2;
                if (a[mid] > med) { ato = mid; }
                if (a[mid] <= med) { mae = mid; }
            }
        }
        static int binary_search(int key, int[] moto)
        {
            int ng = -1;
            int ok = moto.Length;
            while (Math.Abs(ok - ng) > 1)
            {
                int mid = (ok + ng) / 2;
                if (isOK(mid, key, moto)) { ok = mid; }
                else { ng = mid; }
            }
            return ok;
        }
        static bool isOK(int index, int key,int[]moto)
        {
            return moto[index] >= key;
        }

        public static int h;
        public static int w;
        public static int BFS(int height, int width, char[,] map)
        {
            int[] dx = new int[] { -1, 0, 0, 1 };
            int[] dy = new int[] { 0, 1, -1, 0 };
            bool[,] visited = new bool[h, w];
            int[,] len = new int[h, w];
            var queue = new Queue<Tuple<int, int>>();
            queue.Enqueue(new Tuple<int, int>(height, width));
            int max = 0;
            visited[height, width] = true;

            while (queue.Count > 0)
            {
                var now = queue.Dequeue();
                for (int i = 0; i < 4; i++)
                {
                    int ny = now.Item1 + dy[i];
                    int nx = now.Item2 + dx[i];
                    if (ny >= h || ny < 0 || nx >= w || nx < 0)
                        continue;
                    if (visited[ny, nx] || map[ny, nx] == '#')
                        continue;
                    visited[ny, nx] = true;
                    len[ny, nx] = len[now.Item1, now.Item2] + 1;
                    max = Math.Max(max, len[ny, nx]);
                    queue.Enqueue(new Tuple<int, int>(ny, nx));
                }
            }
            return max;
        }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        public char[] Char(int n)
        {
            char[] kore = new char[n];
            for (int i = 0; i < n; i++)
            {
                kore[i] = Char();
            }
            return kore;
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public long[]Long(int n)
        {
            long[] kore = new long[n];
            for (int i = 0; i < n; i++)
            {
                kore[i] = Long();
            }
            return kore;
        }
        public int Integer() { return (int)Long(); }
        public int[]Integer(int n)
        {
            int[] kore = new int[n];
            for (int i = 0; i < n; i++)
            {
                kore[i] = (int)Long();
            }
            return kore;
        }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    public class UnionFind
    {
        public int[] data;

        public UnionFind(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }
    public class Mlong
    {
        private static long mod = 1000000007;
        public long num;
        public Mlong(long num) { this.num = num; }
        public override int GetHashCode()
        {
            return num.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return num.Equals(obj);
        }
        public static Mlong operator +(Mlong x, Mlong y)
        {
            return new Mlong((x.num + y.num) % mod);
        }
        public static Mlong operator -(Mlong x, Mlong y)
        {
            return new Mlong((x.num - y.num + mod) % mod);
        }
        public static Mlong operator *(Mlong x, Mlong y)
        {
            return new Mlong((long)(((1L * x.num) * y.num) % mod));
        }
        public Mlong hutujyo(Mlong x)
        {
            return new Mlong(num / x.num);
        }
        public Mlong modjyo(Mlong x)
        {
            return num * x.Pow(mod - 2);
        }
        public static implicit operator Mlong(long x)
        {
            return new Mlong(x);
        }
        public static Mlong operator %(Mlong x, Mlong y)
        {
            return new Mlong(x.num % y.num);
        }
        public static bool operator ==(Mlong x, Mlong y)
        {
            return x.num == y.num;
        }
        public static bool operator !=(Mlong x, Mlong y)
        {
            return x.num != y.num;
        }
        public static bool operator <(Mlong x, Mlong y)
        {
            return x.num < y.num;
        }
        public static bool operator >(Mlong x, Mlong y)
        {
            return x.num > y.num;
        }
        public static bool operator <=(Mlong x, Mlong y)
        {
            return x.num <= y.num;
        }
        public static bool operator >=(Mlong x, Mlong y)
        {
            return x.num >= y.num;
        }
        public Mlong Pow(Mlong n)
        {

            if (n == 1) { return this % mod; }
            if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
            Mlong buf = Pow(n.hutujyo(2));
            return (buf * buf) % mod;
        }
        public static Mlong Pow(Mlong a, Mlong n)
        {
            return a.Pow(n);
        }
        public static Mlong Comb(Mlong n, Mlong a)
        {
            Mlong buf1 = 1;
            Mlong buf2 = 1;
            for (long i = 0; i < a; i++)
            {
                buf1 *= n - i;
                buf2 *= (i + 1);
            }
            return buf1.modjyo(buf2);

        }
        public static void WriteLine(Mlong x)
        {
            Console.WriteLine(x.num);

        }
    }
    public class Mint
    {
        private static int mod = 1000000007;
        public int num;
        public Mint(int Num) { num = Num; }
        public override int GetHashCode()
        {
            return num.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return num.Equals(obj);
        }
        public static Mint operator +(Mint x, Mint y)
        {
            return new Mint((x.num + y.num) % mod);
        }
        public static Mint operator -(Mint x, Mint y)
        {
            return new Mint((x.num - y.num + mod) % mod);
        }
        public static Mint operator *(Mint x, Mint y)
        {
            return new Mint((int)(((1L * x.num) * y.num) % mod));
        }
        public Mint hutujyo(Mint x)
        {
            return new Mint(num / x.num);
        }
        public Mint modjyo(Mint x)
        {
            return num * x.Pow(mod - 2);
        }
        public static implicit operator Mint(int x)
        {
            return new Mint(x);
        }
        public static Mint[] Toarray(int[] x)
        {
            Mint[] buf = new Mint[x.Length];
            for (int i = 0; i < x.Length; i++)
            {
                buf[i] = x[i];
            }
            return buf;
        }
        public static explicit operator int(Mint x)
        {
            return x.num;
        }
        public static Mint operator %(Mint x, Mint y)
        {
            return new Mint(x.num % y.num);
        }
        public static bool operator ==(Mint x, Mint y)
        {
            return x.num == y.num;
        }
        public static bool operator !=(Mint x, Mint y)
        {
            return x.num != y.num;
        }
        public static bool operator <(Mint x, Mint y)
        {
            return x.num < y.num;
        }
        public static bool operator >(Mint x, Mint y)
        {
            return x.num > y.num;
        }
        public static bool operator <=(Mint x, Mint y)
        {
            return x.num <= y.num;
        }
        public static bool operator >=(Mint x, Mint y)
        {
            return x.num >= y.num;
        }
        public Mint Pow(Mint n)
        {

            if (n == 1) { return this % mod; }
            if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; }
            Mint buf = Pow(n.hutujyo(2));
            return (buf * buf) % mod;
        }
        public static Mint Pow(Mint a, Mint n)
        {
            return a.Pow(n);
        }
        public static Mint Comb(Mint n, Mint a)
        {
            Mint buf1 = 1;
            Mint buf2 = 1;
            for (int i = 0; i < a; i++)
            {
                buf1 *= n - i;
                buf2 *= (i + 1);
            }
            return buf1.modjyo(buf2);

        }
        public static void WriteLine(Mint x)
        {
            Console.WriteLine(x.num);

        }
    }
    public class PriorityQueue<T> : IEnumerable<T>
    {
        private readonly List<T> _data = new List<T>();
        private readonly IComparer<T> _comparer;
        private readonly bool _isDescending;

        public PriorityQueue(IComparer<T> comparer, bool isDescending = true)
        {
            _comparer = comparer;
            _isDescending = isDescending;
        }

        public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
            : this(Comparer<T>.Create(comparison), isDescending)
        {
        }

        public PriorityQueue(bool isDescending = true)
            : this(Comparer<T>.Default, isDescending)
        {
        }

        public void Enqueue(T item)
        {
            _data.Add(item);
            var childIndex = _data.Count - 1;
            while (childIndex > 0)
            {
                var parentIndex = (childIndex - 1) / 2;
                if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
                    break;
                Swap(childIndex, parentIndex);
                childIndex = parentIndex;
            }
        }

        public T Dequeue()
        {
            var lastIndex = _data.Count - 1;
            var firstItem = _data[0];
            _data[0] = _data[lastIndex];
            _data.RemoveAt(lastIndex--);
            var parentIndex = 0;
            while (true)
            {
                var childIndex = parentIndex * 2 + 1;
                if (childIndex > lastIndex)
                    break;
                var rightChild = childIndex + 1;
                if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0)
                    childIndex = rightChild;
                if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
                    break;
                Swap(parentIndex, childIndex);
                parentIndex = childIndex;
            }
            return firstItem;
        }

        public T Peek()
        {
            return _data[0];
        }

        private void Swap(int a, int b)
        {
            var tmp = _data[a];
            _data[a] = _data[b];
            _data[b] = tmp;
        }

        private int Compare(T a, T b)
        {
            return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
        }

        public int Count => _data.Count;

        public IEnumerator<T> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
    }
}