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
import sys
 
N = int(input())
 
listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
 

 
listB = sorted(listA)
la = sorted(listB, key=itemgetter(1))
 
t = 0
for i in range(N):
	s = la[i][1]
	t += la[i][0]
	if t > s:
		print("No")
		sys.exit()
 
print('Yes')

Solution (Python):
n = int(input())
lists = []
limit = []
cost = [0 for _ in range(n)]
for i in range(n):
    a, b = (map(int,input().split()))
    lists.append([a,b])

lists.sort(key = lambda x:x[1])
sum_ = 0
for i in range(n):
    sum_ = sum_ + lists[i][0]
    if sum_ <= lists[i][1]:
        continue
    else:
        print('No')
        exit(0)
print('Yes')

Solution (Python):
n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)], key = lambda x:x[1])


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][0]
    if task_lis[i][1] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i], b[i] = [int(x) for x in input().split()]

tasks = sorted(list(zip(a, b)), key=lambda x: x[1])

is_okay = True
sum = 0
for i in range(N):
    sum += tasks[i][0]

    if sum > tasks[i][1]:
        is_okay = False
        break

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

Solution (Python):
N = int(input())
tasks = sorted([[int(i) for i in input().split()] for _ in range(N)], key=lambda item: item[1])
 
s = 0
for task in tasks:
    s += task[0]
    if task[1] < s:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
sumarray=np.cumsum(z[0][::-1])[::-1]
for i in range(N):
  
  if min(left,z[1,i])<sumarray[i]:
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Solution (Python):

N  = int(input())

AB = []
time = 0

for _ in range(N):
    AB.append(list(map(int, input().split())))

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

for i in range(N):
    time += NewAB[i][0]

    if time > NewAB[i][1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = np.argsort(B)

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Solution (Python):
import math

N = int(input())
task = {}
tasks = []
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    tasks.append((B,A))
    task[B] = A
    
    
    
    

s = 0






for (b,a) in sorted(tasks):
    s += a
    if b<s:
        print('No')
        exit()

print('Yes')

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

work = []
for _ in range(N):
    work.append(list(map(int, input().split())))

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

s_w_l = list(map(lambda x: x[1], s_w))
s_w_c = list(map(lambda x: x[0], s_w))

import numpy as np
if all(np.cumsum(np.array(s_w_c)) <= np.array(s_w_l)):
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np

N = int(input())

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


def yes_or_no():
    sorted_index = np.argsort(B)
    if A[sorted_index[0]] > B[sorted_index[0]]:
        return 0
    sum_A = [A[sorted_index[0]]]
    for i in range(1, N):
        next_num = sum_A[i-1] + A[sorted_index[i]]
        sum_A.append(next_num)
        if next_num > B[sorted_index[i]]:
            return 0
        
    return 1

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

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

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

isYes=True
s=0
for a in sortAB:
    s += a[0]
    if s > a[1]:
        isYes=False
        break

if isYes:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
lis = []
for i in range(n):
    a,b = list(map(int,input().split()))
    lis.append([a,b])
lis.sort(key=lambda x:x[1])
ans = 0
time = 0
for item in lis:
    time += item[0]
    if time > item[1]:
        ans += 1

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

Solution (Python):
def main():
    N = int(input())
    A = [0 for x in range(N)]
    for i in range(N):
        A[i] = list(map(int, input().split(" ")))
    sortedA = sorted(A, key=lambda x: x[1])
    s = [0 for _ in range(N)]
    for i, x in enumerate(sortedA):
        if i == 0:
            s[i] = x[0]
        else:
            s[i] = s[i-1]+x[0]

        if s[i] > x[1]:
            return 'No'
    return 'Yes'


if __name__ == "__main__":
    print(main())

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

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

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

sumW = 0
for a in aaa:
    sumW += a[0]
    if sumW > a[1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
n = int(input())
ab = [tuple(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda ab: ab[1])

t = 0
success = True
for i in range(n):
  t += ab[i][0]
  
  dif = ab[i][1] - t
  if dif < 0:
    success = False
    break

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

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

t = sorted(s, key=lambda x:int(x[1]), reverse = True)

count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  if int(t[i][1]) >= sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
    sum1 = sum1 - int(t[i][0])
if count == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
N = int(input())
tasks = sorted([[int(i) for i in input().split()] for _ in range(N)], key=lambda item: item[1])

s = 0
for task in tasks:
    s += task[0]
    if task[1] < s:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

from collections import defaultdict
import math
import re
import bisect

def main():
    
    N = int(input())
    diff_list = []
    for i in range(N):
        A, B = map(int, input().split())
        diff_list.append((B, A))

    diff_list = sorted(diff_list, key=lambda x: x[0])

    t = 0
    for i in range(N):
        B, A = diff_list[i]
        t += A
        if t > B:
            print("No")
            return

    print("Yes")

if __name__ == '__main__':
    main()

Solution (Python):
import sys

n = int(input())

la = []
for i in range(n):
	a = [int(i) for i in input().split()] 
	la.append(a)

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

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

print("Yes")

Solution (Python):
N=int(input())
A_B=[]
for i in range(N):
    A_B.append(list(map(int,input().split())))
A_B.sort(key=lambda x:x[1])
flag=1
ans=0
for i in range(N):
    ans+=A_B[i][0]
    if ans>A_B[i][1]:
        flag=0
        break
if flag:
    print('Yes')
else:
    print("No")

Solution (Python):


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


data.sort(key=lambda x: x[1])
tmp = 0
for j in range(n):
    tmp += data[j][0]
    if tmp > data[j][1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
n = int(input())
task = []
task_sum = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    task.append([a, b])
task_f = sorted(task, key=lambda x: x[1])

s = 0
flag = True
for i in range(n):
    if s + task_f[i][0] > task_f[i][1]:
        flag = False
        break
    s += task_f[i][0]
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):
N=int(input())
lst=[]

for i in range(N):
    A,B=map(int,input().split())
    lst.append([A,B])
lst.sort(key=lambda x: x[1])

def judge(N):
    worktime=0
    for i in range(N):
        worktime += lst[i][0]
        if worktime > lst[i][1]:
            return('No')
        if (i+1)==N:
            return('Yes')        
print(judge(N))

Solution (Python):
from operator import itemgetter
n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)],key=itemgetter(1))
sum = 0
for a,b in ab:
    sum += a
    if sum > b:
        print('No')
        exit()
print('Yes')

Solution (Python):
def resolve():
    N = int(input())
    ABs = [list(map(int, input().split(" "))) for i in range(N)]
    ABs = sorted(ABs, key=lambda x: x[1])
    time = 0
    for ab in ABs:
        if time + ab[0] > ab[1]:
            print("No")
            return
        time += ab[0]
    print("Yes")

if '__main__' == __name__:
    resolve()

Solution (Python):
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
h = []
mx = 0
for i in range(n):
    x, y = readmi()
    heapq.heappush(h, (-y, -x))
    mx = max(mx, y)
while(h):
    y, x = heapq.heappop(h)
    x = -x
    y = -y
    if mx > y:
        mx = y
    mx -= x
    if mx < 0:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
l = []
for i in range(n):
    c,d = map(int,input().split())
    l.append([c,d])

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

time = 0
ans = "Yes"
for i in range(n):
    limit = l[i][1]
    time += l[i][0]
    if time > limit:
        ans = "No"
        break

print(ans)

Solution (Python):
N = int(input())
A = [0] * N
B = [0] * N
AB = [0] * N
BA = [0] * N
for i in range(N):
    A[i], B[i] = [int(x) for x in input().split()]
    BA[i] = [B[i], A[i]]
list.sort(BA)
t = 0
fail = 0
for n in range(N):
    t += BA[n][1]
    if t > BA[n][0]:
        fail = 1
        break
if fail:
    print('No')
else:
    print('Yes')

Solution (Python):
n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
newlist = sorted(list, key=lambda x:x[1])
x = 0
y = 0
for i in newlist:
	x += i[0]
	if x <= i[1]:
		continue
	else:
		y += 1
		break
if y == 0:
	print('Yes')
else:
	print('No')

Solution (Python):
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[1])
work = 0
for n in range(N):
  work += L[n][0]
  if work > L[n][1]:
    print('No')
    exit()
print('Yes')

Solution (Python):
n = int(input())
lis = []
for i in range(n):
  lis.append(list(map(int,input().split())))
lis.sort(key = lambda tup:tup[1])
t = 0
for item in lis:
  t += item[0]
  if t >item[1]:
    print("No")
    break
else:
  print("Yes")

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])
time=0
for a,b in AB:
    time+=a
    if time>b:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
N = int(input())
L = [[]]
for i in range(N):
    a,b=[int(i) for i in input().split()]
    L.append([a,b])
del L[0]
L = sorted(L, key=lambda x:(x[1]))

def main():
    time = 0
    for n in range(N):
        time += L[n][0]
        if time > L[n][1]:
            print("No")
            return
    print("Yes")
    return

main()

Solution (Python):
n,*t=map(int,open(0).read().split())
c=f=0
for b,a in sorted(zip(t[1::2],t[::2])):c+=a;f|=c>b
print('YNeos'[f::2])

Solution (Python):
import sys
n = int(input())
a= [list(map(int, input().split())) for i in range(n)]

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

sum = 0

for i in range(n):
    if i == 0:
        a[i][0] += 0
    else:
        a[i][0] += a[i-1][0]
    sum += a[i][0]

for i in range(n):
    if a[i][0] > a[i][1]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
def main():
    n = int(input())
    data = [ list(map(int, input().split())) for _ in range(n)]

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

    sum_all = 0
    count = 0

    for i in range(n):
        sum_all += data[i][0]

    if sum_all > int(data[-1:][0][1]):
        return "No"

    for i in range(n):
        count += data[i][0]
        if count > data[i][1]:
            return "No"

    return "Yes"

if __name__ == '__main__':
    print( main() )

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


AB = []

for i in range(n):
    ab = list(map(int, input().split()))
    AB.append(ab)

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



current = 0
ans = True
for i in range(n):
    time = AB[i][0]
    now = current + time

    if now <= AB[i][1]:
        current += time
        continue
    else:
        ans = False
        break

if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
'''for i in range(n):
  x = l[i][1] - l[i][0]
  l[i][2] = x'''
l.sort(key=lambda x: x[1])


check = []
c = 0
for i in range(n):
  if c != l[i][1]:
    check.append(l[i][1])
    c = l[i][1]


sum_t = 0
limit = l[0][1]
ans = 0
for i in range(n):
  if limit != l[i][1]:
    limit = l[i][1]
  sum_t += l[i][0]
  if sum_t > limit:
    ans += 1

if ans == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
n=int(input())
ab=sorted([[int(i) for i in input().split()] for _ in range(n)],key=lambda x:x[1])
now=0
for a,b in ab:
    now+=a
    
    if now>b:
        print("No")
        break
else:
    print("Yes" if now<=ab[-1][1] else "No")

Solution (Python):
from sys import exit

def sfn(a):
    return a[1]
    

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

time=0

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

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

As = []
Bs = []
ABs = []
for _ in range(N):
	A,B = map(int,input().split())
	As.append(A)
	Bs.append(B)
	ABs.append([A,B])
	
if max(Bs) < sum(As):
	print("No")
	exit()
else:
	ABs = sorted(ABs,key=lambda x: (x[1],x[0]))
	
	sum1 = 0
	for i in range(len(ABs)):
		sum1 += ABs[i][0]
		if ABs[i][1] < sum1:
			print("No")
			exit()
	else:
		print("Yes")
		exit()
		
print("Yes")

Solution (Python):
N = int(input())
alllist = []
listtime = []
listtask = []
for i in range(N):
    a,b = map(int,input().split())
    alllist.append([a,b])
sortlist = sorted(alllist, key=lambda x: x[1])

a = 0

for i in range(N):
    a += sortlist[i][0]
    if a > sortlist[i][1]:
        print("No")
        break
else:
    print("Yes")

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

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

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

time = 0
is_no = False
for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
        is_no = True
        break

if is_no:
    print('No')
else:
    print('Yes')

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

tasks = []
for i in range(N) : 
  tasks.append([int(n) for n in input().split()])

tasks.sort(key=lambda x:x[1])
costs = [a[0] for a in tasks]
deadLines = [b[1] for b in tasks]
sumCost = 0

for n in range(len(costs)) :
  sumCost += costs[n]
  dead = deadLines[n]
  if sumCost > dead :
    print("No")
    sys.exit()

print("Yes")

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

A = sorted(A, key=lambda x: x[1])
last = A[N-1][1]
si = 0
for i in range(N):
    si += A[i][0]
    if(si > A[i][1]):
        print('No')
        exit()
print("Yes")

Solution (Python):
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 B < time:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import itertools
import sys

input = sys.stdin.readline


def main():
    
    
    
    
    
    
    
    N = int(input())
    task_list = sorted(
        [[int(i) for i in input().split()] for _ in range(N)], key=lambda x: x[1]
    )
    print(
        "Yes"
        if all(
            [
                j <= i[1]
                for i, j in zip(
                    task_list, itertools.accumulate(map(lambda x: x[0], task_list))
                )
            ]
        )
        else "No"
    )


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
a = []
b = []
w = {}
for _ in range(N):
    A,B = list(map(int,input().split()))
    a.append(A)
    b.append(B)
for i,c in enumerate(b):
    if not c in w.keys():
        w[c] =  [i]
    else:
        w[c].append(i)


wt = 0
for t in sorted(w.keys()):
    
    
    for k in w[t]:
        wt += a[k]
    else:
        pass
        
    if t >= wt:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

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


work = []
for i in range(N):
    A, B = map(int, input().split())
    work.append((A,B))
    


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


sum = 0
flag = 0

for i in range(N):
    sum += work[i][0]

    if(sum>work[i][1]):
        flag = 1
        break
    
if(flag==0):
    print("Yes")
else:
    print("No")

Solution (Python):
from operator import itemgetter

N = int(input())
H=[]
s=0
ans = 0

for i in range(N):
        H.append(list(map(int,input().split())))


H.sort(key=itemgetter(1))

for i in range(N):
    s += H[i][0]
    if H[i][1] < s:
        ans += 1
        break

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

Solution (Python):
N = int(input())
AB = []
asum = 0
bmax = 0
for n in range(N):
  a,b = [int(x) for x in input().split(' ')]
  asum += a
  if bmax <= b:
    bmax = b
  AB.append((a,b))
  
res = 'Yes'
if asum > bmax:
  res = 'No'
else:
  ABsort = sorted(AB,key=lambda x:x[1])
  t = 0
  for x in ABsort:
    a,b = x
    t += a
    if b < t:
      res = 'No'
      break
print(res)

Solution (Python):
import numpy as np
N=int(input())
tasks=[list(map(int,input().split())) for i in range(N)]
able_finish = 'Yes'
time = 0
ts = tasks
ts.sort(key=lambda x:x[1])
for t in ts:
  time += t[0]
  
  if time >t[1]:
    able_finish = 'No'
print(able_finish)

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

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

ABlist = sorted(ABlist, reverse = True)
ABlist = sorted(ABlist, key = lambda x :x[1])


ans = "Yes"
k = 0
for j in range(N):
    k += ABlist[j][0]
    if k > ABlist[j][1]:
        ans = "No"
        break
print(ans)

Solution (Python):
def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(tuple(map(int,input().split(' '))))
    a_sorted = sorted(a,key=lambda x:x[1])
    job_time = 0
    end_time = 0
    for a,b in a_sorted:
        job_time += a
        end_time = b
        if job_time > end_time:
            return 'No'
    return 'Yes'

print(main())

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

AB_list = sorted(AB_list,key=lambda a :(a[1],a[0]))

sumab = 0


for i,ab in enumerate(AB_list):
    if i == 0:
        if ab[1] >= ab[0]:
            sumab = ab[0]
            continue
        else:
            print('No')
            exit(0)

    if sumab + ab[0] <= ab[1]:
        sumab += ab[0]
        
        
    else:
        
        
        print('No')
        exit(0)

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()
time = 0
fin = True
for i in range(N):
    time += BA[i][1]
    if time > BA[i][0]:
        fin = False
if (fin):
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
work = []
for i in range(N):
  work.append(list(map(int, input().split())))
work = sorted(work, key=lambda x: x[1])
time = 0
for i in range(N):
  time += work[i][0]
  if time > work[i][1]:
    print('No')
    exit()
print('Yes')

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

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

a_sum = 0
out = 'Yes'
for ab in AB:
  a_sum += ab[0]
  if a_sum > ab[1]:
    out = 'No'
    break

print(out)

Solution (Python):
import numpy as np
N = int(input())
AB = []
for i in range(N):
    ab = list(map(int,input().split()))
    AB.append(ab)
AB_matrix = np.array([AB])
A = AB_matrix[0]
AB_sort = A[np.argsort(A[:,1])]
now = 0
for j in AB_sort:
    now += j[0]
    if now <= j[1]:
        ans = 'Yes'
    else:
        ans = 'No'
        break
print(ans)

Solution (Python):

N = int(input())
work_list =[]
for i in range(N):
    A,B = map(int,input().split())
    work_list.append([A, B])
work_list.sort(key=lambda x:x[1])
count = 0
ans = "Yes"
for i in range(N):
    count = work_list[i][0]+count
    if count > work_list[i][1]:
        ans = "No"
        break;
print(ans)

Solution (Python):
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])

x=0
for i in range(0,N):
    x=x+D[i][0]
    y=D[i][1]
    if x>y:
        n=1
        break
    else:
        n=0
if n==1:
    print('No')
else:
    print('Yes')

Solution (Python):
n = int(input())
a=[]


for i in range(n):
    s,p=map(int,input().split())
    a+=[[s, p] ]
    

import operator as op
a.sort(key = op.itemgetter(1))


time=0
yyes=True
for i  in range(n):
    time+=a[i][0]
    if(time>a[i][1]):
        yyes=False
        break
    
if yyes:
    print("Yes")
else:
        print("No")

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

a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
d=0
for i in range(n):
    d+=c[i]
    if b[i][0]<d:
        ans="No"
        break
print(ans)

Solution (Python):
from operator import itemgetter
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]
L.sort(key = itemgetter(1))
count = 0
for i in range(len(L)):
    if count + L[i][0] > L[i][1]:
        print('No')
        exit()
    else:
        count += L[i][0]
print('Yes')

Solution (Python):
import heapq
N = int(input())
q = []
time = 0
for x in range(N):
    A , B = map(int, input().split())
    task = (B , A)
    heapq.heappush(q, task)
for y in range(N):
    task = heapq.heappop(q)
    time += task[1]
    if time > task[0]:
        ans = "No"
        break
else:
    ans = "Yes"
print(ans)

Solution (Python):
n = int(input())
a_b = []
for i in range(n):
    a_b.append(list(map(int, input().split())))
a_b = sorted(a_b, key=lambda x: x[1])
a_sum = 0
for i in range(n):
    a_sum += a_b[i][0]
    if a_sum > a_b[i][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
import numpy as np

n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())

A=np.array(b)
c=A.argsort()

time=0

for i in range(n):
    time=time+a[c[i]]
    if time>b[c[i]]:
        print('No')
        break
    if i==n-1 and time<=b[c[i]]:
        print('Yes')

Solution (Python):
N =  int(input())
A =[0]*N
B = [0]*N
for i in range(N):
    A[i] ,B[i] = map(int,input().split())
    
B_sort = sorted(range(len(B)), key=lambda k: B[k])
flag = True
time = 0
for i in B_sort:
    time += A[i]
    if time > B[i]:
        flag = False
        print('No')
        break

if flag:
    print('Yes')

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

stask = sorted(task, key = lambda x: x[1])
time = 0
for i in range(N):
    time += stask[i][0]
    if time > stask[i][1]:
        print('No')
        break
    if i == N-1:
        print('Yes')

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

ab.sort(key=lambda x:x[1])
s = 0
d = []
for i in ab:
    s = s + i[0]
    d.append((i[1],s))
ans = 'Yes'
for i in d:
    if i[0]<i[1]:
        ans = 'No'
print(ans)

Solution (Python):
N=int(input())
T=0
A=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append([a,b])
A.sort(key=lambda x: x[1])

for i in range(N):
    T+=A[i][0]
    if A[i][1]<T:
        ans="No"
        break
    else:
        ans="Yes"
print(ans)

Solution (Python):
n = int(input())
a_lst = []
b_lst = []

for i in range(0, n):
    a, b = [int(elem) for elem in input().split()]
    a_lst.append(a)
    b_lst.append(b)

tmp = zip(b_lst, a_lst)
tmp = sorted(tmp)
b_lst, a_lst = zip(*tmp)   

flag = 0
sums = 0
for i in range(0, len(a_lst)):
    sums += a_lst[i]
    if sums > b_lst[i]:
        flag = 1
        break

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

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

AB=[]
sum_A=0
max_B=0
for _ in range(N):
  a,b=[int(x) for x in input().split()]
  AB.append((a,b))
  sum_A+=a
  max_B=max(max_B,b)
  
if max_B<sum_A:
  print("No")
else:
  sortedAB=sorted(AB,key=lambda x:(x[1],x[0]),reverse=True)
  t=sortedAB[0][1]
  for ab in sortedAB:
    if t > ab[1]:
      t=ab[1]
    t-=ab[0]
    if t < 0:
      print("No")
      break
  else:
    print("Yes")

Solution (Python):
from heapq import heappush, heappop

n = int(input())

tasks = []

for _ in range(n):
  time, delivery = map(int, input().split())
  heappush(tasks, (delivery, time))

now = 0

for _ in range(n):
  delivery, time = heappop(tasks)
  now += time
  if now > delivery:
    print("No")
    break
else:
  print("Yes")

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

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

def abc(a):
    time = 0
    for job in a:
        time += job[0]
        if time > job[1]:
            return 'No'
    return 'Yes'

print(abc(ls))

Solution (Python):
N=int(input())
AB=[0]*N
for i in range(N):
    A,B=map(int,input().split())
    AB[i]=[A,B]
    
AB.sort(key=lambda x:x[1])
nunc=0

for i in range(N):
    nunc+=AB[i][0]
    if nunc>AB[i][1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import numpy as np

N = int(input())
tasks=[]
for i in range(N):
    ab = list(map(lambda x: int(x),input().split()))
    tasks.append(ab)

tasks.sort(key=lambda x: (x[1],-x[0]))
costs = [0]
for i in range(len(tasks)):
  costs.append(costs[-1]+tasks[i][0])


x = np.array(tasks).T[1]
y = np.array(costs[1:])
ans = ""



if len(np.where(x-y<0)[0])>0:
    ans="No"
else:
    ans = "Yes"
print(ans)

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

work.sort()


sum = 0
time = 0

for i in range(len(work)):
    time = time + work[i][1]
    if work[i][0] < time:
        print('No')
        exit()

print('Yes')

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

li.sort(key=lambda x: x[1])
limit = 0
asum = 0
output = 'Yes'
for i in range(n):
  limit = li[i][1]
  asum += li[i][0]
  if asum > limit:
    output = 'No'
    break

print(output)

Solution (Python):
import numpy
frag=True
n=int(input())
t=[list(map(int,input().split())) for _ in range(n)]
t=sorted(t,key=lambda x:x[1])
a=[t[i][0] for i in range(n)]
b=[t[i][1] for i in range(n)]
ar=list(numpy.cumsum(a))
for i in range(n):
  if ar[i] > b[i]:
    frag=False
if frag:
  print("Yes")
else:
  print("No")

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

ab    = []
st_ab = []
a_l   = []
b_l   = []

wt_sum = 0
for i in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
  a_l.append(a)
  b_l.append(b)
  wt_sum += a

if wt_sum > max(b_l):
  print("No")
  exit()

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

wt_sum = 0

a,b = st_ab[0]

for i in range(n):
  a,b = st_ab[i]
  wt_sum += a

  if wt_sum > 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])

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

ans = "Yes"
worktime = 0
for i in range(N):
    worktime += AB[i][0]
    if worktime > AB[i][1]:
        ans = "No"

print(ans)

Solution (Python):



from operator import itemgetter


n = int(input())
tlist = list()

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

tlist.sort(key=itemgetter(1))

etime = 0
ans = "Yes"
for i in range(n):
    etime += tlist[i][0]
    if etime > tlist[i][1]:
        ans = "No"


print(ans)

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

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

B = sorted(A, key = lambda x:x[1])
task = 0
time_1 = 0
flag = 0

for i in range(N):
    task += B[i][0]
    time_1 = B[i][1]

    if task <= time_1:
        pass
    else:
        flag = 1

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

Solution (Python):
def main():
    N = int(input())
    work = []
    time=0
    for i in range(N):
        a,b = map(int,input().rstrip().split(' '))
        ob = {'A': a,'B':b}
        work.append(ob)
    work = sorted(work,key = lambda x: x['B'])
    for w in work:
        time += w['A']
        if time > w['B']:
            print('No')
            return 0
    print('Yes')

if __name__ == "__main__":
    main()