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):
result = "Yes"


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

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

s = 0

for i in range(N):
    if ls[i][0] > ls[i][1]:
        result = "No"
        break
    s += ls[i][0]
    if s > ls[i][1]:
        result = "No"
        break

print(result)

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],x[0]))
time = 0
result = True
for n in range(N):
    if AB[n][1] < time + AB[n][0]:
        result = False
        break
    else:
        time += AB[n][0]
print("Yes") if result else print("No")

Solution (Python):
N = int(input())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    c = 0
    A.append(a)
    B.append(b)
def merge_sort(arr,b):
    if len(arr) <= 1:
        return (arr,b)

    mid = len(arr) // 2
    
    left = arr[:mid]
    right = arr[mid:]
    leftt =b[:mid]
    rightt = b[mid:]

    
    left,leftt = merge_sort(left,leftt)
    right,rightt = merge_sort(right,rightt)

    
    return merge(left, right,leftt,rightt)


def merge(left, right,leftt,rightt):
    merged = []
    mergedd = []
    l_i, r_i = 0, 0

    
    while l_i < len(left) and r_i < len(right):
        
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            mergedd.append(leftt[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            mergedd.append(rightt[r_i])
            r_i += 1

    
    if l_i < len(left):
        merged.extend(left[l_i:])
        mergedd.extend(leftt[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
        mergedd.extend(rightt[r_i:])
    return (merged,mergedd)
B,A = merge_sort(B,A)
found = True
SUM = 0
for i in range(N):
    SUM = SUM + A[i]
    if B[i] < SUM:
        found = False
if found:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(1,N+1):
  inf = input().split()
  a = int(inf[0])
  b = int(inf[1])
  dic[b] += [a]

keys = list(dic.keys())
keys.sort()
ps = 0

for k in keys:
  ls = dic[k]
  need = sum(ls)
  ps += need
  if ps>k:
    print('No')
    break
else:
  print('Yes')

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

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

now = 0

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

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

AB = []

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



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

on_time = True

time = 0
for ab in AB:
    a = ab[0]
    b = ab[1]

    time += a

    if time > b:
        on_time = False

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

Solution (Python):
N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
sortedjobs = list(sorted(jobs, key = lambda x: x[1]))
tott = 0
flag = False
for A, B in sortedjobs:
    tott += A
    if tott > B:
        flag = True
if flag:
    print("No")
else:
    print("Yes")

Solution (Python):




N=int(input())
data=[]
for i in range(N):
    text = input()
    data.append((int(text.split()[0]), int(text.split()[1])))

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


imakonojikan=0

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

print('Yes')


exit(0)

Solution (Python):
N = int(input())
WS = [[int(i) for i in input().split()] for i in range(N)]
WS = sorted(WS, key=lambda x: x[1])
total = 0
for w in WS:
    total += w[0]
    if total > w[1]:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
l = []
for i in range(n):
	a, b = map(int, input().split())
	l.append((a,b))
l.sort(key = lambda x: x[1])
accm = 0
f = 1
for i in range(n):
    accm += l[i][0]
    if accm > l[i][1]:
        f=0
        break
if f: print("Yes")
else: print("No")

Solution (Python):



N= (int(input()))
flag = 0
A_list = []
B_list = []
AB_list = []
for i in range(N):
    a,b= (int(j) for j in input().split())  
    A_list.append(a)
    B_list.append(b)
    AB_list.append([a,b])
    pass
AB_list = sorted(AB_list, key=lambda x: x[1])

now = 0
for ab in AB_list:
   now += ab[0]
   if ab[1] < now:
       flag = 1
       break
   pass
if flag == 1:
    print("No")
else:
    print("Yes")

Solution (Python):

n = int(input())

list_ba = [] 

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

list_ba.sort()

w = 0
rtn = "Yes"
for s in list_ba:
    w += s[1]
    if (w > s[0]):
        rtn = "No"
        break

print(rtn)

Solution (Python):






import numpy as np





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





data = np.array(data)





sorted_data = data[np.argsort(data[:, 1])]
cumsum_data = np.cumsum(sorted_data[:,0])





flag = 0
for i in range(N):
    if cumsum_data[i] > sorted_data[i, 1]:
        flag = 1
        break

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

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

Solution (Python):


n = int(input())

works = []
for _ in range(n):
    works.append(tuple(map(int, input().split())))


works.sort(key=lambda x: (x[1], x[0]))

now = 0 
for work in works:
    now += work[0]
    deadline = work[1]
    if now > deadline:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import sys

n = int(input())

ab = []

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

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

sumA = 0

available = True

for a, b in ab :
    sumA += a
    if sumA>b:
        available = False
        break

if available == False:
    print('No')
else :
    print('Yes')

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

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

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

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

Solution (Python):
import numpy as np

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

task = np.array(task)
task = task[np.argsort(task[:, 1])]

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

print("Yes")

Solution (Python):
import sys

n = int(input())
li = []
for i in range(n):
    li.append(list(map(int, input().split())))
li.sort(key=lambda x:x[1])
total = 0
for i in range(n):
    total += li[i][0]
    if total > li[i][1]:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
import numpy as np

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

b_sort_index = np.argsort(b_list)
time = 0
for i in b_sort_index:
    time += a_list[i]
    if time > b_list[i]:
        print('No')
        exit(0)
print('Yes')

Solution (Python):
n=int(input())
tl=[]
for inp in range(n):
    ab = input().split()
    tl.append((int(ab[1]),int(ab[0])))



tl.sort()



sums=0
for tup in tl:
    sums+=tup[1]
    if tup[0]<sums:
        
        ans="No"
        break
else:
    ans="Yes"

print(ans)

Solution (Python):
import sys

n = int(input())
task_dead = [[0,0]]*(n+1)

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

stack = [0]*(n+1)
for i,task in enumerate(task_dead):
    if i!=0:
        stack[i] = stack[i-1]+task[0]
        if stack[i] > task[1]:
            print('No')
            sys.exit()
print('Yes')

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

time = 0

for i,j in task:
  time += i
  if time > j:
    print('No')
    break
else:
  print('Yes')

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

n = int(input())


ab = [[int(i) for i in input().split()] for _ in range(n)]



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

time = 0

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

print("Yes")

Solution (Python):

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

ab_sorted = sorted(ab,reverse = True)

f = True
next_st = ab_sorted[0][0]
for b,a in ab_sorted:
    if next_st < 0:
        f = False
        break
    elif next_st > b:
        next_st = b-a
    else:
        next_st = next_st-a
    if next_st<0:
        f = False
        break

if f == False:
    print("No")
else:
    print("Yes")

Solution (Python):
n = int(input())
l =[[0]*2 for i in range(n)]
checker = 0
a_ = 0
for i in range(n):
    a,b = map(int, input().split())
    l[i][1] = a
    l[i][0] = b

l = sorted(l)

for i in range(n):
    a_ = a_ + l[i][1]
    if a_ > l[i][0]:
        checker = 1
        break

if checker == 1:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys
from operator import itemgetter


fin = sys.stdin.readline
N = int(fin())
ab_list = [[int(elem) for elem in fin().split()] for _ in range(N)]

ab_list = sorted(ab_list, key=itemgetter(1, 0))

current_time = 0
result = True
for ab in ab_list:
    a, b = ab
    current_time += a
    if current_time > b:
        result = False
        break
if result:
    print('Yes')
else:
    print('No')

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

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

s = 0
y = 0
for i in range(n):
  s += x[i][0]
  if s > x[i][1]:
    y = 1
    print("No")
    break
if y == 0:
  print("Yes")

Solution (Python):
from operator import itemgetter
N=int(input())
jobs=[]
for _ in range(N):
    temp=list(map(lambda x:int(x),input().split()))
    jobs.append((temp[0],temp[1]))

jobs_temp=sorted(jobs,key=itemgetter(0))
jobs_sorted=sorted(jobs,key=itemgetter(1))
now=0
result="No"
for job in jobs_sorted:
    now+=job[0]
    if now>job[1]:
        break
else:
    result="Yes"

print(result)

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

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

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

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,0))
time=0
ans='Yes'
for i in range(n):
  time+=ab[i][0]
  if time>ab[i][1]:
    ans='No'
    break
print(ans)

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

res = 'Yes'
times = 0

for i in range(n):
  times += sorted_t[i][0]
  if times > sorted_t[i][1]:
    res = 'No'
    break

print(res)

Solution (Python):
n=int(input())
i=0
s=[]
a=[]
d=[]
while i!=n:
    a=list(map(int,input().split()))
    d.append(a[1])
    d.append(a[0])

    s.append(d)
    d=[]
    i+=1

s.sort()


ans=0
i=0
x=0
while i!=n:
    ans+=s[i][1]
    if ans>s[i][0]:
        x=1
        break
    i+=1
if x==1:
    print("No")
else:
    print("Yes")

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

time = 0
b = True
for i in range(len(job)) :
	time += job[i][0]
	if (time > job[i][1]) : b = False
if (b) : print("Yes")
else : print("No")

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline






















def main():

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

	time = 0
	for i, val in enumerate(AB):
		a,b = val
		time += a
		if time > b:
			print("No")
			sys.exit()

	print("Yes")




if __name__ == "__main__":
	main()

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

ba = []

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

ba.sort()
totala = 0
totalb = 0

flag = True
for b, a in ba:
    totala += a
    totalb = b
    if totala > totalb:
        flag = False
        break

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

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

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

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

for i in range(1,N):
    AB[i][0]+=AB[i-1][0]

s=0

for i in range(N):
    if AB[i][0]>AB[i][1]:
        s=1

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

Solution (Python):
N = int(input())
task = []
for i in range(N):
  a,b = input().split()
  task.append([int(a),int(b)])
task.sort(key=lambda x:x[0])
task.sort(key=lambda x:x[1])
count = 0
sum = 0
for i in range(N):
  sum = sum + task[i][0]
  if sum > task[i][1]:
    count = 1
    break
if count == 0:
  print("Yes")
else:
  print("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])
time = 0
for i in AB:
    time += i[0]
    if time > i[1]:
        time = "over"
        break
if time == "over":
    print("No")
else:
    print("Yes")

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

L.sort(key=lambda x: (x[1],x[0]))

cnt = 0
flag = True
for i in range(N):
    

    cnt += L[i][0]
    
    if cnt > L[i][1]:
        flag = False
        break

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

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

List = list(list(map(int, input().split())) for i in range(N))



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



S = 0
for j in range(N):
    S += List[j][0]
    if(S > List[j][1]):
        print('No')
        break
else:
    print('Yes')

Solution (Python):
N = int(input())
BAs = {}
for i in range(N):
    A, B = map(int, input().split())
    if not B in BAs:
        BAs[B] = A
    else:
        BAs[B] += A
BAs = sorted(BAs.items())
Bs, As = map(list, zip(*BAs))
for i in range(len(BAs) - 1):
    if As[i] > Bs[i]:
        print('No')
        exit()
    As[i + 1] += As[i]
if As[len(BAs) - 1] > Bs[len(BAs) - 1]:
    print('No')
    exit()
print('Yes')

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

times = []
limits = []
for i in range(num):
	line = input().split(' ')
	times.append(int(line[0]))
	limits.append(int(line[1]))

time_limit = zip(limits, times)
test = sorted(time_limit)

times, limits = [], []
for limit, time in test:
	times.append(int(time))
	limits.append(int(limit))

now = 0
judge = True

for time, limit in zip(times, limits):
	now += time
	if now > limit:
		judge = False
		print('No')
		break

if judge:
	print('Yes')

Solution (Python):
import sys

def sort_nested_list(nested_list):
    nested_list.sort(key = lambda  x: x[1])
    return nested_list

N = int(input())

jobs = [list(map(int, input().split())) for _ in range(N)]
jobs = sort_nested_list(jobs)
time = 0

for job in jobs:
    hours, deadline = job[0], job[1]
    
    time += hours
    
    if time > deadline:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):










import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    n = int(sys.stdin.readline())
    l = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
    l = sorted(l,key=lambda l:l[1])
    t = 0
    for e in l:
        t += e[0]
        if t > e[1]:
            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])

judge=True
time=0

for i in range(n):
        time+=ab[i][0]
        if time>ab[i][1]:
                judge=False
                break

if judge:
        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], x[0]))
s = 0
for t in AB:
    s += t[0]
    if (s > t[1]):
        print('No')
        quit()
print('Yes')

Solution (Python):
N = int(input())
Alist = []
Blist = []
cost = 0
for i in range(N):
    A, B = map(int, input().split())
    Alist.append(A)
    Blist.append(B)
    
k = zip(Blist, Alist)
q = sorted(k)
for i in range(N):
    cost += q[i][1]
    if cost > q[i][0]:
        print("No")
        break
    if i == N-1:
        print("Yes")

Solution (Python):
import sys

N = int(input())
tasks = []
lines = sys.stdin.readlines()
for line in lines:
    temp = [int(i) for i in line.split()]
    
    tasks.append(tuple(temp))

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

for t in tasks:
    time += t[0]
    if time > t[1]:
        print('No')
        sys.exit(0)
print('Yes')

Solution (Python):
n=int(input())
a=[[0,0] for i in range(n)]
for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
a.sort(key=lambda x:x[1])
sa=0
sb=0
count=0
for i in range(n):
    sa+=a[i][0]
    sb=a[i][1]
    if sa>sb:
        print("No")
        break
    else:
        count+=1
if count==n:
    print("Yes")

Solution (Python):
import sys
N=int(input())
listAB=[]
for i in range(N):
  A,B=map(int,input().split())
  listAB+=[[B,A]]  
listAB.sort()
sumA=listAB[0][1]
for i in range(N-1):
  if listAB[i][0]<sumA:
    print("No")
    sys.exit()
  sumA+=listAB[i+1][1]
if listAB[N-1][0]<sumA:
  print("No")
else:
  print("Yes")

Solution (Python):
from sys import stdin

def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * 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')

input = lambda: stdin.readline()
main()

Solution (Python):
import sys

N=int(input())
A=[[0]*2 for i in range(N)]

for i in range(N):
    A[i][0],A[i][1]= map(int,input().split())
sortsecond=lambda val:val[1]

A.sort(key=sortsecond)
sum=0
for i in range(N):
    sum+=A[i][0]
    if sum>A[i][1]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
def dec(X, d):
    X[1] -= d
    return X


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

task.sort(key=lambda x: x[1])
time = 0
for i in range(N):
    time += task[i][0]
    if time > task[i][1]:
        print("No")
        exit()

print("Yes")

Solution (Python):
n=int(input())
ba=[]
for i in range(n):
  c,d=map(int,input().split())
  ba.append([d,c])
ba.sort(key=lambda x:(x[0],-x[1]))
time=0
ans="Yes"
for i in range(n):
  time+=ba[i][1]
  if time<=ba[i][0]:
    continue
  else:
    """print("i",i)"""
    ans="No"
    break
print(ans)

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
A_B = [list(map(int,input().split())) for i in range(N)]
A_B = sorted(A_B,key=itemgetter(1))

s=0
for a_b in A_B:
  s+=a_b[0]
  lim = a_b[1]
  if s > lim:
    print("No")
    exit()
print("Yes")

Solution (Python):
from sys import stdin
def main():
    n = int(input())
    ab = [list(map(int, stdin.readline().split())) for i in range(n)]
    ab.sort(key=lambda x:x[1])
    now = 0
    cnt = 0

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


if __name__=="__main__": main()

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


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


sumab = 0
flag = True
for ab in AB:
    sumab += ab[0]
    if sumab > ab[1]:
        flag = False
        break

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
lab = [0]*n
for i in range(n):
  a,b = map(int,input().split())
  lab[i] = [b,a]

lab.sort()
time = 0
for i in lab:
  time += i[1]
  if time > i[0]:
    print('No')
    exit()
print('Yes')

Solution (Python):
import fractions
import sys

input = sys.stdin.readline

n = int(input())

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

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

flag = True
current_cost = 0
for item in list_dayo:
    current_cost += item[0]
    if current_cost > item[1]:
        flag = False
        break

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

Solution (Python):
N = int(input())
table = []
for _ in range(N):
    a,b = map(int, input().split())
    if a > b:
        print('No')
        exit()
    table.append((a,b))

table = sorted(table, key = lambda x:x[1])
time = 0
for i in range(N):
    a, b = table[i]
    if time > b - a:
        print('No')
        exit()
    time += a
print('Yes')

Solution (Python):

n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)]

e = sorted(e, key=lambda x: x[1])
t=0
flg=0
for i in range(n):
    t+=e[i][0]

    if(t>e[i][1]):
        flg=1
if flg==0:
    print('Yes')
else:
    print('No')

Solution (Python):
from sys import stdin
def main():
    n = int(input())
    ab = [list(map(int, stdin.readline().split())) for i in range(n)]
    ab.sort(key=lambda x:x[1])
    now = 0
    cnt = 0

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


if __name__=="__main__": main()

Solution (Python):
import numpy as np
n = int(input())
ab = []
for _ in range(n):
  ab.append( list(map(int, input().split())) )

nda = np.array(ab)
nda_sort = nda[np.argsort(nda[:, 1])]


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

Solution (Python):
import sys
from operator import itemgetter
n=int(sys.stdin.readline())
task=[]
ans="Yes"
for i in range(n):
    task.append(list(map(int,sys.stdin.readline().split())))
task.sort(key=itemgetter(1))
ryou=0
for i in task:
    ryou+=i[0]
    if i[1]<ryou:
        ans="No"
        break
print(ans)

Solution (Python):

N = int(input())

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

works_info_lst.sort()

A_sum = 0
def judge(works_info_lst, A_sum, N):
    for i in range(N):
        A_sum += works_info_lst[i][1]
        if A_sum > works_info_lst[i][0]:
            return False
    return True

if judge(works_info_lst, A_sum, N):
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
from pprint import pprint

def solve(n, tasks):
    tasks.sort()
    
    spent = 0
    for limit, time in tasks:
        spent += time
        if spent > limit:
            return 'No'

    return 'Yes'

if __name__ == '__main__':

    tasks = []
    n = int(sys.stdin.readline().strip())
    for _ in range(n):
        a, b = map(int, sys.stdin.readline().strip().split(" "))
        tasks.append((b, a))

    print solve(n, tasks)

Solution (Python):
N = int(input())
job = []
sum = 0
result = "Yes"
for _ in range(N):
    cost, limit = map(int, input().split())
    job.append((limit,cost))

job.sort()
for i,j in job:
    sum += j
    if i < sum:
        result = "No"
        break

print(result)

Solution (Python):
import numpy as np
N =int(input())

A = np.zeros((N,2))


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



B = A[A[:,1].argsort(),:]    


sa = B[0,0]
i = 0
while i < N-1 and sa <= B[i,1]:
    i +=1
    sa += B[i,0]


    
if i == N -1 and sa <=B[i,1]:
  
    print('Yes')
else:
    print('No')

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

Solution (Python):
def solve():
    flag = True
    N = int(input())
    schedules = []
    for _ in range(N):
        a,b = input().split(' ')
        schedules.append((int(a),(int(b))))
        
    s_s = sorted(schedules, key=lambda x:x[1])
    time = 0
    for s,limit in s_s:
        time += s;
        if(time > limit): 
            flag = False
            break
    if flag:
        print('Yes')
    else:
        print('No')

solve()

Solution (Python):
from operator import itemgetter

a= int(input())
task = []
for i in range(a):
    task.append(list(map(int,input().split())))
task.sort(key=itemgetter(1))

now = 0
flag = 0
for i in range(a):
    now += task[i][0]
    if now > task[i][1]:
        flag =1
if flag == 0:
    print("Yes")
else:
    print("No")

Solution (Python):

N = int(input())

past_time = 0
flag = True

data = []

for n in range(N):
    A, B = map(int, input().split())
    data.append([B, A])
    
data.sort()

for dd in data:
    A, B = dd[1], dd[0]
    past_time += A
    if past_time > B:
        flag = False
        break

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

Solution (Python):
import sys
input = sys.stdin.readline
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

for i in range(N):
  s += ab[i][0]
  if (s > ab[i][1]):
    print('No')
    exit()
else:
  print('Yes')

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

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

time=0
ans="Yes"

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

print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.zeros((N,2))
for i in range(N):
    A[i] =  np.array(list(map(int,input().split())))

B = A[np.argsort(A[:,1])]
x = 0
for i in range(N):
    x += B[i,0]
    y = B[i,1]
    if x > y:
        print('No')
        break
    else:
        if i == N-1:
            print('Yes')
            break

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

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

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

s = 0
result = True
for v in l:
  s += v[0]
  if s > v[1]:
    result = False
    break

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

Solution (Python):
import numpy as np

n = int(input())
ab = np.zeros((n, 2))

for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    ab[i, 0] = a_tmp
    ab[i, 1] = b_tmp

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

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

print("Yes")

Solution (Python):
import os, sys, re, math

N = int(input())


memo = {}

for _ in range(N):
	A,B = [int(s) for s in input().split(' ')]
	if B in memo:
		memo[B] += A
	else:
		memo[B] = A

s = 0
flg = True
key = list(memo.keys())
key = sorted(key)
for i in range(len(key)):
	s += memo[key[i]]
	if s > key[i]:
		flg = False
		break
if flg:
	print('Yes')
else:
	print('No')

Solution (Python):

n = int(input())
ab = []
for i in range(n):
    line = input().split()
    tmp = []
    tmp.append(int(line[0]))
    tmp.append(int(line[1]))
    ab.append(tmp)
    
ab = sorted(ab, key=lambda x: x[1])
t = 0
pos = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        pos = False
        break
if not pos:
    print('No')
else:
    print('Yes')

Solution (Python):
def sol(inp=input):
    n=int(inp())
    lines=[list(map(int,inp().split())) for _ in range(n)]
    lines=sorted(lines,key=lambda l:l[1])
    
    for i in range(n-1):
        lines[i+1][0]+=lines[i][0]

    return('Yes' if all(l[0]<=l[1] for l in lines) else 'No')

print(sol())

Solution (Python):

import numpy as np
N = int(input())
ls = []
for n in range(N):
  a,b= map(int,input().split())
  ls.append([a,b])
ls = np.array(ls)
idx = np.argsort(ls[:,1])
ls = ls[idx]
sm = 0
for a,b in ls:
  sm += a
  if sm > b:
    print("No")
    exit()
print ("Yes")

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

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

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

s = 0
for i in l:
    s += i[0]
    if s > i[1]:
        print("No")
        exit()
print("Yes")