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 (Python):
from operator import itemgetter
n = int(input())
tasks = [list(map(int, input().split() )) for _ in range(n)]
tasks.sort(key = itemgetter(1))


t = 0
for i in range(n):
	t += tasks[i][0]
	if t > tasks[i][1]:
		print("No")
		exit()

print("Yes")

Solution (Python):
n = int(input())
ba = []
for i in range(n):
    a, b = map(int, input().split())
    ba.append([b, a])
ba.sort()
now = 0
out = 0
for i, j in ba:
    now += j
    if now > i:
        out = 1
        break
if out:
    print("No")
else:
    print("Yes")

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        AB.append((a, b))

    AB.sort(key=lambda x: x[1])

    possible = True
    current = 0
    for a, b in AB:
        current += a
        if current <= b:
            pass
        else:
            possible = False
            break

    print('Yes' if possible else 'No')


if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
from itertools import accumulate
import sys
N = int(input())
AB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
AB.sort(key = itemgetter(1))
A1, B1 = list(map(list, zip(*AB)))
SA = list(accumulate(A1))
if all(a <= b for a, b in zip(SA, B1)):
    print('Yes')
else:
    print('No')

Solution (Python):

def debug(*args):
    import sys
    print(*args, file=sys.stderr)

def solve(N, BA):
    BA = sorted(BA)

    t = 0
    for b, a in BA:
        t += a
        if t > b:
            return "No"
    return "Yes"



def main():
    N = int(input())
    BA = []
    for _ in range(N):
        A, B = [int(x) for x in input().split()]
        BA.append(tuple([B, A]))

    print(solve(N, BA))

main()

Solution (Python):

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    jobs = [tuple(map(int, input().split())) for _ in range(n)]
    jobs.sort(key=lambda x: (x[1], x[0]))

    t = 0
    for cost, deadline in jobs:
        t += cost
        if t > deadline:
            print('No')
            return
    print('Yes')




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, A: "List[int]"):
    A.sort(key=lambda x: x[1])
    current = 0
    for volume, deadend in A:
        current += volume
        if current > deadend:
            print(NO)
            return
    print(YES)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [tuple()] * (N)  
    for i in range(N):
        A[i] = (int(next(tokens)), int(next(tokens)))
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

ab = sorted(AB, key=lambda x:(x[1],x[0]))

now = 0
for a, b in ab:
	if b < now + a:
		print("No")
		break
	else:
		now += a
else:
	print("Yes")

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
now = 0
for a, b in ab:
    now += a
    if now > b:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])

sum = 0
ab.sort(key=lambda x: x[1])
for i in range(n):
    sum += ab[i][0]
    if sum > ab[i][1]:
        print("No")
        exit()
print("Yes")

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    s = S()
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            print("Bad")
            quit()
    print("Good")
    return


def B():
    n,l = LI()
    a = [i+l for i in range(n)]
    ans = sum(a)
    m = n+l-1
    for i in a[::-1]:
        if i < 0:break
        m = min(m,i)
    ans -= m
    print(ans)
    return


def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
def C():
    a,b,c,d = LI()
    g = gcd(c,d)
    l = c*d//g
    sc = b//c-(a-1)//c
    sd = b//d-(a-1)//d
    sl = b//l-(a-1)//l
    print(b-a+1-sc-sd+sl)
    return


def D():
    n = I()
    w = LIR(n)
    w.sort(key = lambda x: x[1])
    t = 0
    for a,b in w:
        if t+a > b:
            print("No")
            quit()
        t += a
    print("Yes")
    return


def E():
    n = I()

    return


def F():
    n = I()

    return


if __name__ == "__main__":
    D()

Solution (Python):

N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]



AB=sorted(AB, key=lambda x: x[1])

time = 0
flag = 0
for i in range(N):
    time+=AB[i][0]
    if time <= AB[i][1]:
        pass
    else:
        flag = 1
        break
        
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
X=sorted([tuple(map(int,input().split())) for i in range(N)],key=lambda x:x[1])
S=0
for i in range(N):
    S+=X[i][0]
    if S<=X[i][1]:
        pass
    else:
        print("No")
        exit()
print("Yes")

Solution (Python):
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    task = [tuple(map(int, input().split())) for _ in range(n)]
    tmp = 0
    task.sort(key=lambda x:x[1])
    for a, b in task:
        tmp += a
        if tmp > b:
            print("No")
            return
    print("Yes")

main()

Solution (Python):
n = int(input())

tasks = [list(map(int, input().split())) for _ in range(n)]

tasks.sort(key=lambda x:x[1])

curr_time = 0

for task, time_limit in tasks:
    curr_time += task
    if curr_time > time_limit:
        print("No")
        exit()

print("Yes")

Solution (Python):
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]

A.sort(key=lambda x:x[1])
S = 0

for a, b in A:
    S += a
    if S > b:
        print('No')
        exit()

print('Yes')

Solution (Python):





n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)] 
ab.sort(key = lambda x: x[1])


now = 0
for a,b in ab:
    now += a
    if now > b:
        print("No")
        break
else: print("Yes")

Solution (Python):
N=int(input())

C=[list(map(int,input().split())) for i in range(N)]

C.sort(lambda x:x[1])

S = 0
flag=True
for i in range(N):
    S+=C[i][0]
    if S>C[i][1]:
        flag=False
        break

if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

N = int(input())

A = [[int(i) for i in input().split()]for _ in range(N)]
A = sorted(A, key=lambda x:x[1])
total = 0
ret = "Yes"
for i in A:
	total += i[0]
	if total > i[1]:
		ret="No"
		break
print(ret)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
BAs = []
for i in range(N):
    A,B = inpl()
    BAs.append([B,A])

BAs.sort()

now = 0
for B,A in BAs:
    now += A
    if now <= B:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

n = int(input())
a = [[int(i) for i in input().split()] for i in range(n)]
a.sort(key = lambda x:x[1])
timer = 0
goodbad = 0
for i in range(n):
    timer += a[i][0]
    if timer > a[i][1]:
        goodbad = 1
if goodbad == 1:
    print("No")
else:
    print("Yes")

Solution (Python):
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1))
t = 0
for a, b in AB:
    t += a
    if t > b:
        print("No")
        exit()
print("Yes")

Solution (Python):
def main():
    N = int(input())
    T = []
    for i in range(N):
        a, b = map(int, input().split())
        T.append((a, b))
    T.sort(key=lambda x: x[1])
    p = 0
    fail = False
    for i in range(N):
        p += T[i][0]
        if p > T[i][1]:
            fail = True
    print('No' if fail else 'Yes')

if __name__ == '__main__':
    main()

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import random
import collections
import math
import itertools
import bisect

def real_main():
    N = read_int()
    jobs = [read_int_array() for _ in range(N)]
    order = mergesort(jobs, key=lambda p: p[1])
    t = 0
    for i in order:
        c, d = jobs[i]
        t += c
        if d < t:
            print("No")
            return
    print("Yes")



def solve():
    pass


def main():
    if False and 'PYCHARM_HOSTED' in os.environ:
        main_pycharm()
    else:
        real_main()


from copy import deepcopy
def main_pycharm():
    solution = solve

    test_inputs = None
    test_outputs = None
    judge = None
    slow_solution = None
    if solution is not None:
        if test_outputs is not None:
            test_with_answers(solution, test_inputs, test_outputs)
        if judge is not None:
            test_with_judge(solution, test_inputs, judge)
        if slow_solution is not None:
            test_with_slow_solution(solution, test_inputs, slow_solution)


def test_with_answers(solution, inputs, answers):
    total, wrong = 0, 0
    for args, test_ans in zip(inputs, answers):
        ans = solution(*deepcopy(args))
        if ans != test_ans:
            print('WRONG! ans=%s, test_ans=%s, args=%s' % (ans, test_ans, args))
            wrong += 1
        else:
            print('GOOD')
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_judge(solution, inputs_gen, judge):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        if not judge(deepcopy(ans), *deepcopy(args)):
            print('WRONG! ans=%s, args=%s' % (ans, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))


def test_with_slow_solution(solution, inputs_gen, solution_slow):
    total, wrong = 0, 0
    for args in inputs_gen:
        ans = solution(*deepcopy(args))
        slow = solution_slow(*deepcopy(args))
        if ans != slow:
            print('WRONG! ans=%s, slow=%s, args=%s' % (ans, slow, args))
            wrong += 1
        total += 1
    print('ALL %d TESTS PASSED' % total if not wrong else '%d out of %d tests are WRONG' % (wrong, total))




def mergesort(A, key=lambda x: x, reverse=False):
    C = A
    A = list(range(len(A)))
    B = list(A)

    n = len(A)
    for i in range(0, n - 1, 2):
        if key(C[A[i]]) > key(C[A[i ^ 1]]):
            A[i], A[i ^ 1] = A[i ^ 1], A[i]

    width = 2
    while width < n:
        for i in range(0, n, 2 * width):
            R1, R2 = min(i + width, n), min(i + 2 * width, n)
            j, k = R1, i
            while i < R1 and j < R2:
                if key(C[A[i]]) > key(C[A[j]]):
                    B[k] = A[j]
                    j += 1
                else:
                    B[k] = A[i]
                    i += 1
                k += 1
            while i < R1:
                B[k] = A[i]
                k += 1
                i += 1
            while k < R2:
                B[k] = A[k]
                k += 1
        A, B = B, A
        width *= 2

    if reverse:
        A.reverse()
    return A




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

def read():
    return input()

def read_int():
    return int(input())

def read_array(sep=None, maxsplit=-1):
    return input().split(sep, maxsplit)

def read_int_array():
    return [int(a) for a in read_array()]



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
Tasks = [list(map(int, input().split())) for i in range(N)]

Tasks.sort(key=lambda x: x[1])

now = 0
for a, b in Tasks:
    if now + a > b:
        print('No')
        break
    now += a
else:
    print('Yes')

Solution (Python):

import sys
sys.setrecursionlimit(300000)

YES = "Yes"  
NO = "No"  

def solve(N: int, A: "List[int]", B: "List[int]"):
    p = []
    for i in range(N):
        p.append([A[i], B[i]])
    p.sort(key=lambda x: x[1])
    tmp = 0
    ret = YES
    for i in range(N):
        tmp += p[i][0]
        if tmp > p[i][1]:
            ret = NO
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()
ws = []
for i in range(n):
    ws.append(na())

ws.sort(key=lambda x: x[1])
t = 0
for w in ws:
    t += w[0]
    if t > w[1]:
        print("No")
        sys.exit(0)
print("Yes")

Solution (Python):
def main():
    N = int(input())
    jobs = [None] * N
    for i in range(N):
        A, B = map(int, input().split())
        jobs[i] = (B, A)
    jobs.sort()
    t = 0
    for B, A in jobs:
        t += A
        if t > B:
            print("No")
            return
    print("Yes")

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
arr=[]
for i in range(n):
	a,b=map(int,input().split())
	arr.append((b,a))
arr.sort()
time=0
flag=0
for i in range(n):
	if(time+arr[i][1]>arr[i][0]):
		flag=1
		break
	else:
		time+=arr[i][1]

if(flag==0):
	print('Yes')
else:
	print('No')

Solution (Python):
from operator import itemgetter

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

a.sort(key=itemgetter(1))

p = 0

for i in range(n):
    p+=a[i][0]
    if p>a[i][1]:
        print('No')
        exit()

print('Yes')

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    AB = LLIN(N)
    AB.sort(key=lambda x: x[1])
    now = 0
    for a, b in AB:
        if b - now >= a:
            now += a
        else:
            print("No")
            exit()
    print("Yes")
if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
X = []
for _ in range(N):
    a, b = map(int, input().split())
    X.append((a,b))

X = sorted(X, key = lambda x:x[1])
t = 0
for i in range(N):
    t += X[i][0]
    if t > X[i][1]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    AB = []
    for _ in range(N):
        a, b = LI()
        AB.append([b, a])
    AB.sort()
    ans = True
    time = 0
    for b, a in AB:
        time += a
        if time > b:
            ans = False
            break
    ans = YesNo(ans)
    return ans

print(main())

Solution (Python):
import sys
input = sys.stdin.readline

N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

NOW=0
for x,y in AB:
    NOW+=x
    if NOW>y:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import numpy as np

N = int(input())
AB = np.array([[int(x) for x in input().split()] for _ in range(N)])
A = AB[:,0]
B = AB[:,1]
idx = B.argsort()
A = A[idx]
B = B[idx]
np.cumsum(A, out = A)
bl = (A <= B).all()
answer = 'Yes' if bl else 'No'
print(answer)

Solution (Python):
N=int(input())
task=[tuple(map(int,input().split())) for i in range(N)]
task.sort(key=lambda x:x[1])
now=0
flag=True
for a,b in task:
    now+=a
    if now>b:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = list(map(int, input().split()))
a.sort(key = lambda x: x[1], reverse = True)


now = a[0][1]
for time, lmt in a:
    now = min(now, lmt)
    now -= time
if now < 0:
    print("No")
else:
    print("Yes")

Solution (Python):

import sys


import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    ab = ip.SILS(n)
    id.S(ab, 1, 1)
    ab = np.array(ab)
    memo = ab.sum(axis=0)[0]
    res = memo
    f = False
    for i, x in e(ab):
        if res <= x[1]:
            res -= x[0]
        else:
            f = True
            break
    if f:
        print("No")
    else:
        print("Yes")


main()

Solution (Python):
import numpy as np
n=int(input())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
x=np.argsort(b)
g=0
f=0
for i in range(n):
    g+=a[x[i]]
    if b[x[i]]<g:
        f+=1
if f>0:
    print('No')
else:
    print('Yes')

Solution (Python):
N=int(input())
L=[list(map(int,input().split())) for i in range(N)]
L.sort(key=lambda x:x[1])
cr=0
chk=1
ll=0
for i in range(N):
  a,b=L[i]
  cr+=b-ll-a
  if cr<0:
    chk=0
    break
  ll=b
  
print("Yes" if chk else "No")

Solution (Python):
n=int(input())
w=[[int(_) for _ in input().split()] for __ in range(n)]
w.sort(key=lambda x: x[1])
t=0
for i in range(n):
    t += w[i][0]
    if t > w[i][1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
from operator import itemgetter
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = itemgetter(1))
now = 0
ans = "Yes"
for i in ab:
    a,b = i[0],i[1]
    now += a
    if now > b:
        ans = "No"
        break
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort(key=lambda x: (x[1],-x[0]))
time=0
for a,b in AB:
    time+=a
    if time>b:
        print('No')
        break
else:
    print('Yes')