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):
N=int(input())
li_=[]
for i in range(N):
  A,B=map(int,input().split())
  li_.append((B,A))
li_.sort()
time=0
for i in range(N):
  time+=li_[i][1]
  if time>li_[i][0]:
    print("No")
    exit()
print("Yes")

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

ab = zip(b,a)
ab = sorted(ab)
b,a = zip(*ab)

val = 0
ans  = "Yes"
for i in range(n):
    val +=a[i]
    if val > b[i]:
        ans = "No"
        break
print(ans)

Solution (Python):
import sys
N = int(input())
BA = []
for _ in range(N):
    a, b = map(int, input().split())
    BA.append([b, a])
BA.sort()
time=0
for i in range(N):
    time+=BA[i][1]
    
    if time>BA[i][0]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
import sys

n = int(input())
work = [list(map(int, input().split())) for i in range(n)]
work = sorted(work, key=lambda x:x[1])

sum = 0

for i in range(n):
  sum += work[i][0]
  if sum > work[i][1]:
      print('No')
      sys.exit()

print('Yes')

Solution (Python):
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""


t=ii()
lol=[] 
ans=0
for _ in range(t):
    a,b=ml()    
    lol.append([b,a])
lol.sort()
f=0
for i in range(t):
    if(lol[i][1]+ans<=lol[i][0]):
        ans+=lol[i][1]
    else:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

Solution (Python):
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""


t=ii()
lol=[] 
ans=0
for _ in range(t):
    a,b=ml()    
    lol.append([b,a])
lol.sort()
f=0
for i in range(t):
    if(lol[i][1]+ans<=lol[i][0]):
        ans+=lol[i][1]
    else:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    Q=[]
    for _ in range(N):
        a,b=MI()
        Q.append([b,a])
        
    Q.sort()
    now=0
    flag=1
    for i in range(N):
        b,a=Q[i]
        now+=a
        if now>b:
            flag=0
            break
            
    if flag:
        print("Yes")
    else:
        print("No")
        

main()

Solution (Python):
n=int(input())
a=[]
b=[]
for _ in range(n):
    c=list(map(int,input().split()))
    a.append(c[0])
    b.append(c[1])
d=list(zip(b,a))
d.sort()


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

Solution (Python):
import numpy as np
N = int(input())
A_list =[0]*N
B_list =[0]*N
for i in range(N):
    A_list[i],B_list[i] = map(int,input().split())
x = np.argsort(B_list)
A_list = np.array(A_list)[x]
B_list = np.array(B_list)[x]
ans = 0
for i,j in zip(A_list,B_list):
    ans +=i
    if(ans<=j):
        pass
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
import numpy
N = int(input())
task = numpy.array([list(map(int, input().split())) for _ in range(N)])
task = task[numpy.argsort(task[:, 1])]

ans = 'Yes'

time = 0
for j in task:
    time += j[0]
    if time > j[1]:
        ans = 'No'
        break

print(ans)

Solution (Python):

from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N = I()
    AB = sorted(LIR(N), key=lambda x: x[1])

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
   N = int(input())
   T = [list(map(int, input().split())) for i in range(N)] 
   S = [[b, a] for a,b in T]
   U = sorted(S)
   time = 0
   for b, a  in U:
        time += a
        if time > b:
           print('No')
           return
   print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
import sys

n=int(input())
ba=[[0]*2 for i in range(n)]
for i in range(n):
    ai,bi=map(int,input().split())
    ba[i]=[bi,ai]
    
ba.sort() 

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

Solution (Python):
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[1])
S=0
T=True
for i in range(N):
    S+=A[i][0]
    if A[i][1]<S:
        T=False
if T==True:
    print("Yes")
else:
    print("No")

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

W = sorted(W,key =lambda x:(x[1],x[0]))
now = 0
for w in W:
  
  if now +w[0] > w[1]:
    print("No")
    exit()
  now+=w[0]
print("Yes")

Solution (Python):
from collections import deque
n = int(input())
task = deque()
now = 0
for i in range(n):
  task.append(tuple(map(int, input().split())))
task = deque(sorted(task, key = lambda x: x[1]))
while True:
  work = task.popleft()
  now+=work[0]
  if now>work[1]:
    print('No')
    break
  if len(task) == 0:
    print('Yes')
    break

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

B=list(set(B))
B.sort()

time=0
ans='Yes'
break_flag = False

for b in B:
    if break_flag:
        break
    for a in A[b]:
        time += a 

        if b < time:
            ans='No'
            break_flag = True
            break
        
print(ans)

Solution (Python):
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]
AB_sorted = sorted(AB, key=lambda x: x[1])
task_sum = 0
ans = 'Yes'

for i in range(N):
  task_sum += AB_sorted[i][0]
  if task_sum > AB_sorted[i][1]:
    ans = 'No'
    break
print(ans)

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

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

flag = 1
total = 0

for i in lis:
    total += i[0]
    if total > i[1]:
        flag = 0
        break

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

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

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

flag = 1
total = 0

for i in lis:
    total += i[0]
    if total > i[1]:
        flag = 0
        break

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

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

Solution (Python):
N=int(input())
list=[]
for i in range(N):
  a,b=map(int,input().split())
  list.append((b,a))
list.sort()
acc=0
for i in range(N):
  acc+=list[i][1]
  if acc>list[i][0]:
    print('No')
    exit()
print('Yes')

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


S={}
for i in range(n):
    a,b = map(int,input().split())
    if b in S:
        S[b]+=a
    else:
        S[b]=a
    
S2=sorted(S.items())
wa=0
for i in range(len(S2)):
    s,w = S2[i]
    wa+=w
    if s<wa :
        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])

s = 0

flag = True

for a, b in ab:
    s += a
    if s > b:
        flag = False
        break

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

Solution (Python):
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = list(zip(B, A))
C.sort()
B, A = zip(*C)
t = 0
for c in C:
    t += c[1]
    if t <= c[0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

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

ab.sort(key = lambda x: x[1])
ok = True
last = 0
for a,b in ab:
    if b-a>=last:
        last += a
    else:
        ok = not ok
        break
print('Yes' if ok else 'No')

Solution (Python):
n = int(input())
ab = []
for i in range(n):
    ai, bi = map(int,input().split())
    abi = [ai,bi]
    ab.append(abi)
sorted_ab = sorted(ab,key=lambda x : x[1])

fin = 0
for j in range(n):
    fin += sorted_ab[j][0]
    if fin > sorted_ab[j][1]:
        print("No")
        quit()
print("Yes")

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

for i in range(n):
    ai, bi = list(map(int, input().split()))
    tasks.append((ai, bi))

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

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

print("Yes")

Solution (Python):
n=int(input())
a=[]
for _ in range(n):
  b=list(map(int,input().split()))
  a.append(b)
  
a.sort(key=lambda x: x[1])

ans=0
ch=0

for c in range(n):
  x=a[c][0]
  y=a[c][1]
  
  ans+=x
  if ans>y:
    ch+=1
  
if ch==0:
  print('Yes')
else:
  print('No')

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

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

schedule = sorted(schedule, key=lambda x: x[1])
ans = 0
end = 0

flg = True
for i in range(N):
    end += schedule[i][0]
    if end <= schedule[i][1]:                   
         continue
    flg = False

print("Yes" if flg else "No")

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

worklist.sort(key=lambda x: x[1])
timecount = 0
count = 0

for i in range(n):
    timecount += worklist[i][0]
    if timecount > worklist[i][1]:
        count += 1

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

Solution (Python):
from operator import itemgetter
N=int(input())
ab=[tuple(map(int,input().split())) for _ in range(N)]
ab=sorted(ab, key=itemgetter(1))


c=0
for v in ab:
    if c+v[0]<=v[1]:
        c+=v[0]
    else:
        print('No')
        break
else:
    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()

tm = 0
flg = True
for b, a in ba:
    if tm + a <= b:
        tm += a
    else:
        flg = False

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

Solution (Python):
from sys import exit
N = int(input())
L = []
for _ in range(N):
  L.append(list(map(int, input().split())))
L.sort(key=lambda  x: x[1])
used = 0
for l in L:
  used += l[0]
  if used > l[1]:
    print("No")
    exit()
print("Yes")

Solution (Python):
n=int(input())
l=[tuple(map(int, input().split())) for i in range(n)]
l.sort(key=lambda x:x[1])
cnt=0
for t in l:
    cnt+=t[0]
    if cnt>t[1]:
        print('No')
        exit()

print('Yes')

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

Solution (Python):
N=int(input())
L=[list(map(int,input().split())) for _ in range(N)]
L.sort(key=lambda x:x[1])
t=0
p=True
for l in L:
  t+=l[0]
  if t > l[1]:
    p=False
    break
print("Yes" if p else "No")

Solution (Python):


def main():
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]
    AB.sort(key=lambda x: x[1])
    work = 0
    ans = 'Yes'
    for i in range(N):
        work += AB[i][0]
        if work > AB[i][1]:
            ans = 'No'
            break
    print(ans)


if __name__ == "__main__":
    main()

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

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

AB.sort()

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

print("Yes")

Solution (Python):
import sys
import math


N = int(input())

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

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

sum_time = 0
for i in timelis:
    need = i[0]
    deadline = i[1]

    sum_time = sum_time + need

    if sum_time > deadline:
        print("No")
        sys.exit()

print("Yes")

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

t=a[0][1]
for x in a:
    t=min(x[1],t)-x[0]
print("Yes" if t>=0 else "No")

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

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

ans="Yes"
sum_A=0
for i in range(N):
    sum_A+=AB[i][0]

    if sum_A>AB[i][1]:
        ans="No"
        break

print(ans)

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

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

for i in range(N):
    cnt += tsk[i][0]
    if cnt > tsk[i][1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
ab = [[] for _ in range(n)]
for i in range(n):
    ab[i] = list(map(int, input().split()))
ab.sort(key=lambda x: x[1])
r = 0
flag = True
for a, b in ab:
    r += a
    if r > b:
        flag = False
        break

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

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

Solution (Python):
n=int(input())
tab = []
for i in range(n):
	a,b = map(int,input().split())
	tab+=[[a,b]]
	
def cle(x):
	return x[1]
tab.sort(key = cle)

ans = "Yes"

temps = 0
for a,b in tab:
	temps+=a
	if temps>b: ans = "No"
	
print(ans)

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

A = []

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

def Sort(F): 
  
    
    
    
    F.sort(key = lambda x: x[1]) 
    return F 

A = Sort(A)

date = 0

for i in range (0, N):
	if date + A[i][0] > A[i][1]:
		print('No')
		exit()
	else:
		date+=A[i][0]

print('Yes')

Solution (Python):
n=int(input())
l=[list(map(int,input().split()))[::-1] for _ in range(n)]
l.sort()
t=0

ans="Yes"
for m in l:
  t+=m[1]
  if t>m[0]:
    ans="No"
print(ans)

Solution (Python):
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[1])

memo = 0
flag = True
for a,b in ab:
    memo += a
    if b < memo:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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])
m = 0
ans = "Yes"
for ai,bi in ab:
    m += ai
    if m > bi:
        ans = "No"
print(ans)

Solution (Python):











def solve(n,l):
  l = sorted(l,key=lambda x: x[1])
  consumedTime = 0
  flag = True
  for i in range(n):
    if not flag:
      break
    consumedTime += l[i][0]
    if consumedTime > l[i][1]:
      flag = False
  return flag



def main():
  N = int(input())
  
  l = [tuple(map(int,input().split())) for _ in range(N)]
  print("Yes" if solve(N,l) else "No")
  return

if __name__ == '__main__':
  main()

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

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

Solution (Python):
n = int(input())
a = [0] * n
b = [0] * n
arr = [[0] * 2 for _ in range(n)]

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

arr.sort()
time = 0
flag = True
for i in range(n):
    time += arr[i][1]
    if time > arr[i][0]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
N = int(input())
BA = [None] * N
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    BA[i] = (b, a)
BA.sort()

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

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

AB = sorted(AB, key=lambda x: x[1])
time = 0
for job in AB:
    
    time += job[0]
    
    if time > job[1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda x: x[1])
su = 0
for i in A:
    su += i[0]
    if su > 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])
comp = []
for lst in ab:
    comp.append(lst[1])
acc = [0]
for i, v in enumerate(ab):
    acc.append(acc[-1] + v[0])
for x, y in zip(acc[1:], comp):
    if x > y:
        print("No")
        break
else:
    print("Yes")

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

t = 0
for i, (b, a) in enumerate(tsk):
    t += a
    if t > b:
        print('No')
        exit()
else:
    print('Yes')

Solution (Python):
n=int(input())
task=[]
for _ in range(n):
  a, b=map(int, input().split())
  task.append([a,b])
task.sort(key=lambda x:x[1])

cula=0
for a, b in task:
  cula+=a
  if cula>b:
    print("No")
    exit()
print("Yes")

Solution (Python):
ABs = []

N = int(input())
for _ in range(N):
    ABs.append(tuple(map(int,input().split())))

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

sum = 0
for A, B in ABs:
    sum += A
    if sum > B:
        print('No')
        exit()
print('Yes')

Solution (Python):
ABs = []

N = int(input())
for i in range(N):
    ABs.append(tuple(map(int,input().split())))

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

sum = 0
for A, B in ABs:
    sum += A
    if sum > B:
        print('No')
        exit()
print('Yes')

Solution (Python):
ABs = []

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

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

sum = 0
for pair in ABs:
    sum += pair[0]
    if sum > pair[1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from operator import itemgetter

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

C.sort(key=itemgetter(1))

elapsed = 0
for i in range(N):
    elapsed += C[i][0]
    if elapsed > C[i][1] :
        print("No")
        exit(0)

print("Yes")

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

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

Solution (Python):

import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    tasks = []

    for i in range(N):
        task = LI()
        tasks.append([task[1], task[0]])
    tasks.sort()

    sum_time = 0

    for task in tasks:
        sum_time += task[1]
        if sum_time > task[0]:
            print("No")
            return

    print("Yes")


main()

Solution (Python):
N = int(input())
X = [[int(_) for _ in input().split()] for _ in range(N)]

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

t = 0
for a, b in X:
    t += a
    if t > b:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
import sys
from itertools import combinations_with_replacement, product
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    task=[]
    for _ in range(N):
        A,B=map(int, input().split())
        task.append([A,B])
    task.sort(key=lambda x: x[1])
    task=np.array(task)
    task[:,0]=task[:,0].cumsum()
    if all(task[:,0] <= task[:,1]):
        print('Yes')
    else:
        print('No') 

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N =int(input())
AB = []
for i in range(N):
    a,b = map(np.int64,input().split())
    AB.append((b,a))

AB.sort()
time = np.int64(0)

for b,a in AB:
    if time +a >b:
        print("No")
        exit()
    time +=a
    
print("Yes")

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

AB.sort()
time =0

for b,a in AB:
    if time +a >b:
        print("No")
        exit()
    time +=a
    
print("Yes")

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(N: int, A: "List[int]", B: "List[int]"):
    acc = 0
    for b, a in sorted(zip(B, A)):
        acc += a
        if b < acc:
            return NO
    return YES


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))
    print(solve(N, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

time = 0
for b, a in task:
    time += a
    if time > b:
        print("No")
        quit()
print("Yes")

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

if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N = cin()
A = []
for i in range(N):
    in1, in2 = cin()
    A.append([in2, in1])

A = sorted(A)
t = 0
flg = 1
for i in range(N):
    t += A[i][1]
    if t > A[i][0]:  flg = 0
if flg:  print("Yes")
else:  print("No")

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

time = 0
for i in range(n):
    simekiri, sigoto = lst[i][0],lst[i][1]
    time += sigoto
    if time <= simekiri:
        continue
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):

n = int(input())
s = [[*map(int, input().split())] for i in range(n)]
s.sort(key=lambda x: x[1])
c = 0
for a, b in s:
    c += a
    if c > b:
        print("No")
        exit()
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])
time=0
for A,B in AB:
    time+=A
    if time>B:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = [list(map(int, readline().rstrip().split())) for _ in range(n)]
    A.sort(key=lambda x: x[1])
    sumTime = 0
    maxTime = 0
    for arr in A:
        maxTime = arr[1]
        sumTime += arr[0]
        if maxTime - sumTime < 0:
            print("No")
            return
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
d=[]
for _ in range(n):
  a,b=map(int,input().split())
  d+=[(b,a)]
d=sorted(d)
t=0
for i,j in d:
  if j+t>i:
    print('No')
    break
  t+=j
else:print('Yes')

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

N=int(input().rstrip('\n'))
s = {}
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  if B in s:
    s[B] += A
  else:
    s[B] = A
m = sorted(list(set(s)))
check = 0
used = 0
for i in m:
  used += s[i]
  if used > i:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

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

AB = sorted(AB,key=lambda x:x[1])
t=0
for i in range(N):
  ab=AB[i]
  t += ab[0]
  if t > ab[1]:
    print('No')
    exit()
print('Yes')

Solution (Python):
n = int(input())
d = {}
s = 0
for i in range(n):
    a, b = map(int, input().split())
    if b not in d:
        d.update({b:a})
    else:
        d[b] += a
    s += a
key = list(d.keys())
key.sort(reverse = True)
ans = True
for k in key:
    if k < s:
        ans = False
        break
    s -= d[k]
if ans:
    print("Yes")
else:
    print("No")

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

X=[0]*N
for k in range(1,N+1):
    a,b=map(int,input().split())
    X[k-1]=(a,b)

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

D=0
F=True
for (s,t) in X:
    D+=s
    F&=D<=t

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

Solution (Python):
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
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])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
import numpy as np
n = int(input())
A = np.array([list(map(int,input().split())) for _ in range(n)])
s = np.argsort(A[:,1])
A = A[s]
aa = 0
ans = 'Yes'
for a,b in A:
    aa += a
    if aa > b:
        ans = 'No'
        break
print(ans)

Solution (Python):
import numpy as np
n = int(input())
A = np.array([list(map(int,input().split())) for _ in range(n)])
s = np.argsort(A[:,1])

A = A[s]
a = 0
ans = 'Yes'
for i in range(n):
    a += A[i,0]
    b = A[i,1]
    if a > b:
        ans = 'No'
        break
print(ans)

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

total = 0
for si in s:
    total += si[0]
    if total > si[1]:
        print('No')
        exit()
print('Yes')

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

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

t = 0
for a,b in ab:
  t += a
  if t > b:
    print("No")
    exit()
print("Yes")

Solution (Python):
import sys
N = int(input())
V = [list(map(int, input().split())) for _ in range(N)]
V.sort(key=lambda x: x[1])
s = 0
for v in V:
    s += v[0]
    if s > v[1]:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
N = int(input())
T = list()
for _ in range(N):
    a, b = map(int, input().split())
    T.append((a, b))
T = sorted(T, key=lambda x:x[1])

Time = 0 
for task in T:
    taskTime, deadline = task
    Time += taskTime
    if deadline < Time:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
sa = []
for i in range(n):
  a,b = list(map(int, input().split()))
  if ( a > b ):
    print('No')
    exit()    
  sa.append({'a': a, 'b': b})

sa.sort(key=lambda x: x['b'])

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

print('Yes')

Solution (Python):
n = int(input())
sa = []
for i in range(n):
  a,b = list(map(int, input().split()))
  if ( a > b ):
    print('No')
    exit()    
  sa.append({'a': a, 'b': b})

sa.sort(key=lambda x: x['b'])

aa = 0

for i in range(n):
  aa = aa + sa[i]['a']
  b = sa[i]['b']
  if (aa > sa[i]['b']):
    print('No')
    exit()

print('Yes')

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

arr = []

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

arr.sort()

now = 0

for a in arr:
	if now + a[1] > a[0]:
		print("No")
		exit()
	now += a[1]

print("Yes")

Solution (Python):
N = int(input())
tasks = [None] * N

for i in range(N):
  tasks[i] = tuple(map(int,input().split()))

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

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