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

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

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


t = 0
f = 0
for a,b in ab_list:
    
    t += a
    if t > b:
        f = 1
        break

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

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

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


tmp = sorted(works, key=lambda x: x[0], reverse=True)
sorted_works = sorted(tmp, key=lambda x: x[1])

current_hour = 0
ans = "Yes"
for required_hour, dead_line in sorted_works:
    current_hour += required_hour
    if dead_line < current_hour:
        ans = "No"
print(ans)

Solution (Python):
def resolve():
    import numpy as np
    N = int(input())
    A = np.array([list(map(int, input().split())) for __ in range(N)])
    l = A[np.argsort(A[:, 1])]

    t = 0
    for i in l:
        t += i[0]
        if t > i[1]:
            print('No')
            return
    print('Yes')

resolve()

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



from operator import itemgetter
  
dat2 = sorted(dat, key=itemgetter(1))





t = 0
for i in range(n):
    t += dat2[i][0]
    if t > dat2[i][1]:
        print("No")
        break
else:
    print("Yes")

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


li = []

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

flag = True
now = 0
li = sorted(li)

for a, b, c in li:
    now += b
    if now > c:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

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

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

cnt=0
ans='Yes'
for k,v in a:
    cnt+=k
    if cnt>v:
        ans='No'
        break
print(ans)

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], x[0]))

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

print('Yes')

Solution (Python):
import sys
from operator import itemgetter

input = sys.stdin.readline
n = int(input())
tasks = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))

time = 0
cando = True
for task in tasks:
  time += task[0]
  if time > task[1]:
    cando = False
    
print('Yes' if cando else 'No')

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

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

s = 0

for i in range(n):
    s += li[i][0]
    if li[i][1] < s:
        print("No")
        break
else:
    print("Yes")

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

ct = 0
for i in j:
  ct += i[1]
  if ct > i[0]:
    print("No")
    break
else:
  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], x[0]))

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

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline
N = int(input())
tasks = [tuple(map(int, input().split())) for _ in range(N)]
tasks.sort(key=itemgetter(1))
start = 0

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

print('Yes')

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

for i in range(n):
  line = list(map(int, input().split()))
  items.append({'a':line[0], 'b':line[1]})
  
sorted_items = sorted(
  items,
  key = lambda x: (x['b'],x['a'])
)


sum = 0
answord = 'Yes'

for i in range(n):
  sum += sorted_items[i]['a']
  if sum > sorted_items[i]['b']:
    answord = 'No'
    break
    
print(answord)

Solution (Python):
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    inp = [int(x) for x in input().split()]
    A[i] = inp[0]
    B[i] = inp[1]

def sort(index):
    if len(index) <= 1:
        return index
    
    min_i = []
    max_i = []

    for i in index[1:]:
        if(B[i] < B[index[0]]):
            min_i.append(i)
        elif(B[i] > B[index[0]]):
            max_i.append(i)
        else :
            if (A[i] <= A[index[0]]):
                min_i.append(i)
            else:
                max_i.append(i)
    max_i.append(index[0])
    
    result = sort(min_i)
    result = result + sort(max_i)

    return result

si = sort(list(range(N)))
total = 0
for i in si:
    total += A[i]
    if(total > B[i]):
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys

n = int(input())
ab_list = [list(map(int, input().split())) for _ in range(n)]
ab_list.sort(key=lambda i: i[1])
time = 0
for a, b in ab_list:
    time += a
    if time > b:
        print('No')
        sys.exit()
print('Yes')

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

hoge.sort()
  
for i in range(n):
  
  time+=hoge[i][1]
  if(time>hoge[i][0]):
    ans+=1
    
if(ans==0):
  print("Yes")
else:
  print("No")

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])
t=0
f=True
for i in range(n):
    t+=l[i][0]
    if t>l[i][1]:
        f=False
if f:
    print("Yes")
else:
    print("No")

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

from operator import itemgetter
              
se = sorted(e, key=itemgetter(1))

flg = 0
sm = 0
for i in range(N):
	sm += se[i][0]
	if sm > se[i][1]:
		print('No')
		break

if i == N-1 and sm <= se[N-1][1]:
	print('Yes')

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

listJob = []
sumAmount = 0
for i in range(N):
    amount, timelimit = map(int, input().split(' '))
    listJob.append((amount, timelimit))
    sumAmount += amount

listJob.sort(key=lambda x: x[1], reverse=True)

def code(listJob, _sumAmount):
    sumAmount = _sumAmount
    currentTime = listJob[0][1]
    for i in listJob:
        currentTime = min(currentTime, i[1])
        sumAmount -= i[0]
        currentTime -= i[0]
        if currentTime < sumAmount:
            return "No"
    return "Yes"

print(code(listJob, sumAmount))

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())

BAList=[]
for i in range (N):
  A,B = map(int,stdin.readline().rstrip().split())
  BAList.append((B,A))

BAList.sort()
deadend=0
jobsum=0
for (B,A) in BAList:
  deadend=B
  jobsum+=A
  if jobsum>deadend:
    print('No')
    exit()
print('Yes')

Solution (Python):
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche ={}
for work in works:
    if work[1] not in sche:
        sche[work[1]] = work[0]
    else:
        sche[work[1]] += work[0]
acc = 0
sche = sorted(sche.items(), key=lambda x:x[0])

for k,v in sche:
    acc += v
    if acc > k:
        print("No")
        exit()

print("Yes")

Solution (Python):

N = int(input())

BA = []

for i in range(N):

    A,B = map(int,input().split())

    BA.append ([B,A])


BA.sort()


time = 0
flag = True
for i in BA:

    time += i[1]

    if time > i[0]:
        flag = False

if flag:
    print("Yes")

else:
    print ("No")

Solution (Python):
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
p.sort(key = lambda x:x[1])
t = 0
ans = 'Yes'
for a, b in p:
    t += a
    if t > b:
        ans = 'No'
        break
print(ans)

Solution (Python):
n = int(input())
p = []
t = 0
ans = 'Yes'
for _ in range(n):
    a,b = map(int,input().split())
    p.append([a,b])

p = sorted(p, key=lambda x:x[1])
for a,b in p:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)

Solution (Python):
N=int(input())
listA=[list(map(int,input().split())) for i in range(N)]
listA.sort(key=lambda x:x[1])
jikan=0
deki=True
for i in range(N):
    jikan=jikan+listA[i][0]
    if jikan > listA[i][1]:
        deki=False
if deki:
    print('Yes')
else:
    print('No')

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

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

time = 0
ans = "Yes"
for ab in AB:
  time += ab[0]
  if time > ab[1]:
    ans = "No"
    break
print(ans)

Solution (Python):


import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N)]

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

flag = True
time = 0
for l in L:
    time += l[0]

    if time > l[1]:
        flag = False
        break

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

Solution (Python):
from operator import itemgetter

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

job = sorted(job, key=itemgetter(0), reverse=True)
job = sorted(job, key=itemgetter(1))

now = 0
des = True
for i, j in enumerate(job):
    j_time = j[0]
    j_dead = j[1]
    now += j_time
    if now > j_dead:
        des = False

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

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

S = [[int(i) for i in input().split()] for i in range(N)] 
S.sort(key=lambda x : (x[1]))

sum = 0
for i in range(N):
    sum += S[i][0]
    if sum > S[i][1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
n=int(input())
AB=[]
TMP=[]
cnt=0
key=True
for i in range(n):
    a,b=map(int,input().split())
    TMP.append(a)
    TMP.append(b)
    AB.append(TMP)
    TMP=[]
AB=sorted(AB, key=lambda x: x[1])
for i in range(n):
    cnt+=AB[i][0]
    if AB[i][1]<cnt:
        key=False
        
if key==True:
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
    N = int(input())
    A = []
    B = []
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        AB.append((a, b))
    if sum(A) > max(B):
        print('No')
        return
    AB = sorted(AB, key=lambda x: x[1])
    c = 0
    for a, b in AB:
        c += a
        if c > b:
            print('No')
            return
    print('Yes')


main()

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

x = []
y = []

for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

x, y = np.array(x), np.array(y)

idx = np.argsort(y)
x = x[idx]
y = y[idx]

t = 0
for i in range(n):
    t += x[i]
    if y[i] < t:
        print("No")
        quit()
print("Yes")

Solution (Python):


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

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

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

Solution (Python):
N = int(input())
A_B = [[int(i) for i in input().split()] for _ in range(N)]
A_B.sort(key=lambda x:x[1])

time = 0
for i in A_B:
  time += i[0]
  if time > i[1]:
    print('No')
    exit()

print('Yes')

Solution (Python):
n=int(input())
d=[]
for _ in range(n):
  a,b=map(int,input().split())
  d.append([a,b])
l=sorted(d,key=lambda x: x[1])
z='Yes'
s=0
for i in range(n):
  s+=l[i][0]
  if s>l[i][1]:
    z='No'
    break
print(z)

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

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

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

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

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

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

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

t = 0
t_limit = 0
task_s = sorted(task, key=lambda x: x[1])
ans = 1

for i in range(N):
    t += task_s[i][0]
    t_limit = task_s[i][1]

    if(t > t_limit):
        ans = 0
        break

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

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_a = 0
ans = 0

for i in range(N):
    sum_a += work[i][0]
    if sum_a > work[i][1]:
        ans = 1
        break


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

Solution (Python):
N=int(input())
works=[]
for i in range(N):
    [a,b]=[int(_) for _ in input().split()]
    works.append([b,a])
works.sort()
works2=works[:1]
for work in works[1:]:
    if work[0]==works2[-1][0]:
        works2[-1][1]+=work[1]
    else:
        works2.append([work[0],works2[-1][1]])
        works2[-1][1]+=work[1]

if all([work[0]>=work[1] for work in works2]):
    print('Yes')
else:
    print('No')

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


li = []

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

flag = True
now = 0
li = sorted(li)

for a, b, c in li:
    now += b
    if now > c:
        print("No")
        flag = False
        break
        
if flag:
    print("Yes")

Solution (Python):
n=int(input())
li=[]
for i in range(n):
    a,b=map(int,input().split())
    li.append([b,a])
    
li.sort()
y="Yes"
sum=0
for i in range(len(li)):
    sum+=li[i][1]

    if li[i][0]<sum:
        y="No"
        break
        
print(y)

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])
s = 0
k = "Yes"
for i in range(n):
    s += ab[i][0]

    if ab[i][1] < s:
         k = "No"
         break
print(k)

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],reverse=True)

time = AB[0][1]
for i in range(1,N):
    if time-AB[i-1][0] < AB[i][1]:
        time = time-AB[i-1][0]
    else:
        time = AB[i][1]

time = time - AB[N-1][0]

if time < 0:
    print("No")
else:
    print("Yes")

Solution (Python):
n = int(input())
a, b = [], []
tmp_a, tmp_b = 0, 0
time_count = 0
result = 0

for i in range(n):
    tmp_a, tmp_b = map(int, input().split())
    a.append(tmp_a)
    b.append(tmp_b)

sort_data = zip(a, b)
sort_data = sorted(sort_data, key=lambda x:x[1])
a, b = zip(*sort_data)

for i in range(n):
    time_count += int(a[i])
    if time_count <= b[i]:
        result = 1
    else:
        result = 0
        break

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

Solution (Python):
n = int(input())
l = [[0,0] for _ in range(n)]

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

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

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

Solution (Python):
n = int(input())
a = []
for _ in range(n):
    x, y = map(int, input().split())
    a.append((x, y))
a.sort(key = lambda x:x[1])
time = 0
flag = 0
for x in a:
    if time + x[0] <= x[1]:
        time += x[0]
    else:
        flag = 1
if flag:
    print("No")
else:
    print("Yes")

Solution (Python):
import math
from fractions import gcd


class Work():

    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __lt__(self, other):
        return self.b < other.b

    def __eq__(self, other):
        return self.b == other.b

    def __repr__(self):
        return "Work(%d, %d)" % (self.a, self.b)


def read():
    N = int(input().strip())
    works = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        works.append(Work(a, b))
    return N, works


def solve(N, works):
    works = sorted(works)
    t = 0
    for work in works:
        t += work.a
        if t > work.b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append((A,B))
t = 0
flag = True
for (A, B) in sorted(AB, key = lambda x:x[1]):
    t += A
    if t > B:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = sorted(
        [list(map(int, input().rstrip().split())) for _ in range(n)], key=lambda x: x[1]
    )
    task_sum = 0
    for i, j in arr:
        task_sum += i
        if task_sum > j:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

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

n = int(input())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([b-a,b,a])
li.sort(reverse=True,key=itemgetter(1))
for i in range(n-1):
    if li[i][0] < li[i+1][1]:
        li[i+1][1] = li[i][0]
        li[i+1][0] = li[i+1][1] - li[i+1][2]
if li[-1][0] < 0:
    print("No")
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])

flag = True
t = 0
for i in range(n):
    t += ab[i][0]
    if t>ab[i][1]:
        flag = False
        break

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

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

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



now = 0
for work in ab_sort:
    if now + work[0] <= work[1]:
        now += work[0]
    else:
        print('No')
        exit()
print('Yes')

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
possibility = 1

for l in AB:
  if l[0] + time > l[1]:
    possibility = 0
    break
  else:
    time += l[0]
    
if possibility == 1:
  print("Yes")
else:
  print("No")

Solution (Python):
import heapq

N = int(input())

works = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(works, (b, a,))

time = 0
can = True
for i in range(N):
    work = heapq.heappop(works)
    time += work[1]
    if time > work[0]:
        can = False
        break

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

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

Solution (Python):
n = int(input())
ab_list = [[int(i) for i in input().split()] for _ in range(n)]
ab_list.sort(key=lambda x:x[1])
t_sum = 0
flag = 0
a_before = 0
for a, b in ab_list:
  t_sum += a
  if b < t_sum:
    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])
t = 0
for sc in ab:
    t += sc[0]
    if t > sc[1]:
        print("No")
        exit()
print("Yes")

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

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

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

from operator import itemgetter

A = sorted(A, key=itemgetter(1))

t = 0
ans = 'Yes'

for a, b in A:
    t += a
    if t > b:
        ans = 'No'
        break

print(ans)

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

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

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

cumulative_times = []
t = 0
for job in jobs:
	t += job[0]
	cumulative_times.append(t)

flag = True
for job, c in zip(jobs, cumulative_times):
	if c > job[1]:
		flag = False

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

Solution (Python):

N=int(input())

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

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

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

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

time = 0
for i in sorted(li):
    time += i[1]
    if time > i[0]:
        print("No")
        quit()

print("Yes")

Solution (Python):
N = int(input())
l = [None]*N
s = []
for i in range(N):
    k = list(map(int,input().split()))
    if k[0]==k[1]:
        s.append(k)
        l[i] = [0,0]
    else:
        l[i] = k

if len(s)>1:
    print("No")
else:
    l = sorted(l, key=lambda x: x[1])
    cnt = 0
    if len(s)==1:
        cnt += s[0][1]

    flag = True
    for j in l:
        if j==[0,0]:
            continue
        else:
            cnt += j[0]
        if cnt>j[1]:
            print("No")
            flag = False
            break
    if flag:
        print("Yes")

Solution (Python):
import sys
from operator import itemgetter
n=int(input())
a=[tuple(map(int,input().split())) for _ in range(n)]
a.sort(key=itemgetter(1))
tm=0
for i in range(n):
    tm+=a[i][0]
    if tm>a[i][1]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
def ddprint(x):
  if DBG:
    print(x)

n = inn()
ba = []
for i in range(n):
    a,b = inm()
    ba.append((b,a))
ba.sort()
sum = 0
for i in range(n):
    b,a = ba[i]
    sum += a
    if sum>b:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
BA = [[0] * 2 for i in range(N)]
for i in range(N):
    A, B = map(int, input().split())
    BA[i][0] = B
    BA[i][1] = A

BA.sort()
t = 0
ans = 'Yes'

for ba in BA:
    B = ba[0]
    A = ba[1]
    t += A
    if t > B:
        ans = 'No'
        break

print(ans)

Solution (Python):
import sys

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

    A = sorted(A, key=lambda x: x[1])
    time = 0
    for a, b in A:
        time += a
        if time > b:
            return 'No'

    return 'Yes'


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

Solution (Python):
N = int(input())
A = []
B = []
C = []
now = 0

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

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

Flag = False

for i in range(N):
    now += C[i][0]
    if now > C[i][1]:
        Flag = True
        break

if Flag == True:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys
N = int(input().strip())
lines = sorted([list(map(int, line.strip().split())) for line in sys.stdin], key=lambda x:x[1])
now_time = 0
for l in lines:
  now_time += l[0]
  if now_time > l[1]:
    print('No')
    exit()
print('Yes')

Solution (Python):
N = int(input())
AB = []
for n in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])
AB.sort(key=lambda x:x[1])
t = 0
c = 0
for i in AB:
    t += i[0]
    if t>i[1]:
        break
    c += 1
if c<len(AB):
    print('No')
else:
    print('Yes')

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

Solution (Python):
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return 'No'
    return 'Yes'


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

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

hour=0
task=0
for i in range(N):
    hour=kekka[i][0]
    task+=kekka[i][1]
    if hour <task:
        print("No")
        break
    if i==N-1:
        print("Yes")

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

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

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



curTime = 0
f = False

for i in l:
    curTime += i[0]

    if curTime > i[1]:
        f = True
        break


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

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ABs = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
    ABs = sorted(ABs, key=lambda x: (x[1], x[0]))
    now = 0
    for A, B in ABs:
        now += A
        if B < now:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

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


now=0
for i in range(n):
    now+=b[i][0]
    if now>b[i][1]:
        print("No")
        quit()

print("Yes")

Solution (Python):
from operator import itemgetter

N = int(input())

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

l.sort(key=itemgetter(0), reverse=True)
l.sort(key=itemgetter(1))

current_time = 0
for n, m in l:
    current_time += n
    if current_time > m:
        ans = 'No'
        break
    else:
        ans = 'Yes'

print(ans)

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

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

works.sort(key=lambda w: w[1])

t = 0
for w in works:
    t += w[0]
    if w[1] < t:
        print('No')
        exit()

print('Yes')

Solution (Python):
from operator import itemgetter

N = int(input())
X = [[int(x) for x in input().split()] for _ in range(N)]
X.sort(key=itemgetter(1))
sum = 0

for i in range(N):
    sum += X[i][0]
    if sum > X[i][1]:
        print("No")
        quit()
print("Yes")

Solution (Python):
n = int(input())
l = [[0,0] for i in range(n)]
for i in range(n):
    a,b = map(int,input().split())
    l[i][0],l[i][1] = b,a
l.sort()
c = 0
for i in range(n):
    c += l[i][1]
    if c <= l[i][0]:
        continue
    else:
        break
if i == n-1 and c <=l[i][0]:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

N = int(input())

w = []

limit = 0

for _ in range(N):

    ai, bi = map(int, input().split())
    w.append((ai, bi))

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

now = 0
for v in w:
    limit = v[1]
    now += v[0]
    if now > limit:
        print('No')
        sys.exit()

print('Yes')

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

lst.sort()
lst = lst + [[0, 0]]

time = lst[0][1]
i = 0
while i < N and time <= lst[i][0]:
    time += lst[i+1][1]
    i += 1

if i == N:
    print('Yes')
else:
    print('No')

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

time = 0
for A, B in sorted(ABs, key=lambda x: x[1]):
    time += A
    if time > B:
        print('No')
        break
else:
    print('Yes')

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

ABlist = []

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

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

ans = "Yes"
Asum = 0

for i in ABlist:
    Asum += i[0]
    if(Asum > i[1]):
        ans = "No"
        break
    
print(ans)

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

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