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):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
jobs = [tuple(map(int, input().split())) for _ in range(N)]
jobs.sort(key=lambda t: t[1])
t = 0
for a, b in jobs:
    t += a
    if t > b:
        print('No')
        exit()
print('Yes')

Solution (Python):

import sys
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
time = 0
for work in ab:
    if time+work[0] <= work[1]:
        time+=work[0]
    else:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
import sys
from heapq import heappush, heappop


def main():
    n=int(input())
    ba=[]
    for i in range(n):
        a,b=map(int,input().split())
        ba.append((b,a))
    ba.sort()
    asum=0
    ans='Yes'
    for b,a in ba:
        asum+=a
        if asum>b:
            ans='No'
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
N = int(input())
AB = []
sumJ = 0
maxK = 0
for i in range(N):
  a,b = map(int,input().split())
  AB.append([a,b])
AB = sorted(AB, key=itemgetter(1))
for j,k in AB:
  sumJ += j
  maxK = max(k,maxK)
  if sumJ > maxK:
    print("No")
    exit()
print("Yes")

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

n = int(input())
ba = [list(map(int,input().split()[::-1])) for _ in range(n)]

ba.sort()

time = 0
for tmp in ba:
    b,a = tmp
    time += a
    if(b < time):
        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])

time = 0
ans = True
for i in a:
  time += i[0]
  if i[1] < time:
    ans = False
    break

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

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

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

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

key = 0
ans = True
for i in range(n):
  if key + work[i][1]> work[i][0]:
    ans = False
    break
  key += work[i][1]

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

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

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

c = sum([i for i,j in ab])
abmax = max([j for i,j in ab])

ab.reverse()
ans = "Yes"
x = c + 0
for i,j in ab:
    if not x <= j:
        ans = "No"
        break
    x -= i

print(ans)

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
AB = np.array([lr() for _ in range(N)])
AB = AB[np.argsort(AB[:, 1])]
A = AB[:, 0]
B = AB[:, 1]
bl = np.all(A.cumsum() <= B)
print('Yes' if bl else 'No')

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

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

print(res)

Solution (Python):
import sys

from collections import Counter
from copy import deepcopy
from itertools import combinations
from operator import itemgetter

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

    
    a.sort(key = itemgetter(1))
    
    time = 0
    for i in range(n):
        time += a[i][0]
        if time > a[i][1]:
            print('No')
            exit()
    else:
        print('Yes')

if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
AB = [lr() for _ in range(N)]
AB.sort(key=lambda x: x[1])
answer = 'Yes'
time = 0
for i in range(N):
    if time + AB[i][0] > AB[i][1]:
        answer = 'No'
    time += AB[i][0]

print(answer)

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

Solution (Python):



from math import *
from copy import *
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize
from operator import *				
from itertools import *
from collections import Counter		
from collections import defaultdict 

'''
5
2 4
1 9
1 8
4 9
3 12
'''

def solve(l):
	n = len(l)
	l = sorted(l)
	
	last = 0
	for i in range(n):
		last += l[i][1]
		if(last > l[i][0]):
			return 'No'
	return 'Yes'
	

N = int(stdin.readline())
L = []
for _ in range(N):
	a,b = list(map(int, stdin.readline().rstrip().split()))
	L.append([b,a])
ans = solve(L)
print(ans)

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

jobs.sort(key=lambda x: x[1])
t = 0
for a, b in jobs:
    t += a
    if t <= b:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

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

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

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

Solution (Python):
N = int(input())
P = [0]*N

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

Solution (Python):
from sys import stdin

N = int(stdin.readline().rstrip())
tasks = []
ans = 'Yes'

for i in range(N):
    t, d = (int(x) for x in stdin.readline().rstrip().split())
    tasks.append((t, d))

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

total = 0
for x, y in tasks:
    total += x
    if total > y:
        ans = 'No'

print(ans)

Solution (Python):
N = int(input())
H = []
for _ in range(N):
    A, B = map(int,input().split())
    H.append((B, A))
H.sort()
t = 0
for i in range(N):
    B, A = H[i]
    t += A
    if B < t:
        print("No")
        break 
    if i == N - 1:
        print("Yes")

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

Solution (Python):

from operator import itemgetter 
from itertools import accumulate
def main():
    n = int(input())
    d = []
    for _ in range(n):
        x, y = map(int, input().split())
        d.append((x, y))
    d.sort(key=itemgetter(1))
    acc = 0
    f = True
    for i in range(n):
        acc = acc+d[i][0] 
        if acc > d[i][1]:
            f = False
    if f:
        print('Yes')
    else:
        print('No')
main()

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

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

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

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

Solution (Python):
n=int(input())
l=sorted([list(map(int,input().split())) for nd in range(n)],key=lambda x: x[1])
now=0
for a,s in l:
  if a+now>s:print("No");exit()
  now+=a
else:print("Yes")

Solution (Python):
ab = sorted([list(map(int,input().split())) for _ in range(int(input()))], key=lambda x:(x[1],x[0]))
time = 0
for l in ab:
  time += l[0]
  if time > l[1]:
    print("No")
    quit()
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],x[0]))
time = 0
for l in ab:
  time += l[0]
  if time > l[1]:
    print("No")
    quit()
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])
Atime = [0]
for i in range(N) :
    Atime.append(Atime[i]+AB[i][0])

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

print("Yes")

Solution (Python):
n = int(input())
jobs = []
for _ in range(n):
  a,b  = map(int,input().split())
  jobs.append((a,b))
  
jobs.sort(key = lambda x: x[1])
time = 0
for i in range(n):
  a,b = jobs[i]
  time += a
  if time <= b:
    continue
  else:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
n = int(input())
list_score = [[] for i in range(n)]

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

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

score = 0
ans = "Yes"
for i, j in list_score:
    score += i
    if score > j:
        ans = "No"

print(ans)

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],)
time = 10000000000
for i in range(len(work)):
    x = work.pop()
    time = min(time,x[1])-x[0]
    if time < 0:
        print('No')
        exit()
print('Yes')

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

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

time = 0
for a, b in ab:
    time += a

    if time > b:
        print("No")
        exit()

print("Yes")

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

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

lefttime = ab[0][1]
for a, b in ab:
    lefttime = min(lefttime, b)
    lefttime -= a
    
    if lefttime < 0:
        print("No")
        exit()

print("Yes")

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

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

A.sort()

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

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

A.sort()

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

Solution (Python):
import sys
import operator
N = int(input())
tasks = []
time = 0
ans = "Yes"

for cmd in sys.stdin:
  a,b = map(int, cmd.strip("\n").split())
  tasks.append([a,b])
tasks.sort(key=operator.itemgetter(1))

for task in tasks:
  time += task[0]
  deadline = task[1]
  if time > deadline:
    ans = "No"
    break

print(ans)

Solution (Python):
def main():
    n = int(input())
    L = [list(map(int,input().split())) for _ in range(n)]
    L.sort(key = lambda x: x[1])
    time = 0
    for a, b in L:
        time += a
        if time > b:
            print('No')
            return
    print('Yes')
main()

Solution (Python):
def main():
    n = int(input())
    L = [list(map(int,input().split())) for _ in range(n)]
    L.sort(key = lambda x: x[1])
    now = 0
    for l in L:
        now += l[0]
        if now > l[1]:
            print('No')
            return
    print('Yes')
main()

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

x.sort(key=lambda x:(x[1],x[0]))
t=0
ans='Yes'
for i in range(n):
    if t+x[i][0]<=x[i][1]:
        t+=x[i][0]
    else:
        ans='No'
        break
print(ans)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
a=[]
for _ in range(int(input())):
    inp=[int(i) for i in input().split()]
    inp.reverse()
    a.append(inp)
a.sort()
t=0 ; flag=0
for i in a:
    t+=i[1]
    if t>i[0]:
        flag=1
        break
if flag==0: print('Yes')
else: print('No')

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

task_list = []
ab = [tuple(map(int,input().split())) for i in range(n)]

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

time = 0
for a,b in ab:
    time += a
    if time > b:
        print('No')
        exit()

print('Yes')

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


now = 0
for i in range(N):
    A,B = AB[i]
    if now+A <= B:
        now += A
    else:
        now = -1
        break
if now == -1:
    print('No')
else:
    print('Yes')

Solution (Python):


N = int(input())
T = []
for i in range(N):
    T.append([int(x) for x in input().split()])
T = sorted(T, key=lambda x:x[1])

total = 0
ans = 'Yes'

for a, b in T:
    total += a
    if total > b:
        ans = 'No'
        break

print(ans)

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

def main():
    current = 0
    for i in range(N):
        current += X[i][0]
        if current > X[i][1]:
            print('No')
            return
    print('Yes')
    return

main()

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

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

t = 0
for a, b in jobs:
    t += a
    if t > b:
        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])

now = 0
ok = True
for necessary, deadline in AB:
    
    
    if now + necessary > deadline:
        ok = False
        break
    now += necessary

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

Solution (Python):
n = int(input())
info = []
ok = True
for _ in range(n):
    a, b = map(int, input().split())
    info.append([a, b])
info.sort(key=lambda x: x[1])
Sum = 0
for i in range(n):
    Sum += info[i][0]
    
    if Sum > info[i][1]:
        ok = False

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

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


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


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

print('Yes')

Solution (Python):
from operator import itemgetter
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab, key=itemgetter(1,0))


time=0
for todotime,deadline in ab:
    time += todotime
    if not (time <= deadline) :
        print('No')
        exit()
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 i in range(N):
  t += AB[i][0]
  if t > AB[i][1]:
    print("No")
    exit()
print("Yes")

Solution (Python):
n = int(input())
a,b = [],[]
d = dict()
s = set()
for i in range(n):
    bn,an = map(int,input().split())
    a.append(an)
    b.append(bn)
    if an not in d.keys():
        d.setdefault(an,bn)
    else:
        d[an] += bn

    s.add(an)

s = list(s)
s.sort()

counter = 0

for i in s:
    counter += d[i]
    if counter > i:
        print("No")
        break
else:
    print("Yes")

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

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

cnt=0
for i in range(N):
  cnt+=L[i][0]
  if L[i][1]<cnt:
    print('No')
    exit()
  
    
print('Yes')

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

Solution (Python):

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

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

Solution (Python):






from operator import attrgetter, itemgetter


import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    ab = [[0] * 2 for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int,ipti().split()))

    ab.sort(key=itemgetter(1))
    time = 0

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


if __name__ == '__main__':
    main()

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

T = sorted(T, key=lambda x:x[1])
t = 0
for a, b in T:
  t += a
  if t > b:
    print("No")
    quit()
print("Yes")

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007



def main():
	n = int(input())
	ddd=[]
	for _ in range(n):
		a,b=IN()
		ddd.append([a,b])
	ddd=sorted(ddd, key=lambda vv : vv[1])
	cc=0
	for a,b in ddd:
		
		cc += a
		if cc > b:
			return 'No'
		
	return 'Yes'
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n = int(input())
BA = [[0, 0] for i in range(n)]
for i in range(n):
    BA[i][1], BA[i][0] = map(int, input().split())
ans = 'Yes'

BA_ = sorted(BA)
t = 0
for i in range(n):
    t += BA_[i][1]
    if t>BA_[i][0]:
        ans = 'No'
        break
print(ans)

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

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

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1 
    
if flag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
from operator import itemgetter

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

job.sort(key = itemgetter(1))

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1    
    
if flag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

n = int(sys.stdin.readline())
m = map(int, sys.stdin.read().split())
ab = list(zip(m, m))

ab.sort(key=lambda x: x[1])
ans = 'Yes'
time = 0
for a, b in ab:
    time += a
    if time > b:
        ans = 'No'
        break
print(ans)

Solution (Python):
from sys import stdin

N = int(stdin.readline())
Job = [None]*N
for i in range(N):
    Job[i] = tuple(map(int, stdin.readline().split()))[::-1]

Job.sort()

Now = 0
for i in range(N):
    Deadline = Job[i][0]
    Now += Job[i][1]
    if Now > Deadline:
        print("No")
        quit()

else:
    print("Yes")

Solution (Python):
from sys import stdin

N = int(stdin.readline())
Job = [None]*N
for i in range(N):
    Job[i] = tuple(map(int, stdin.readline().split()))[::-1]

Job.sort()

Now = 0
for i in range(N):
    Deadline = Job[i][0]
    Now += Job[i][1]
    if Now > Deadline:
        print("No")
        quit()

else:
    print("Yes")

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

T = sorted(T, key=lambda x:x[1])
t = 0
for a, b in T:
  t += a
  if t > b:
    print("No")
    quit()
print("Yes")

Solution (Python):
def main():
    N=int(input())
    AB=[0]*N
    for i in range(N):
        ab=list(map(int,input().split()))
        AB[i]=ab
    AB.sort(key=lambda x:x[1])
    t=0
    flag=True
    for i in range(N):
        t+=AB[i][0]
        if t>AB[i][1]:
            print("No")
            flag=False
            break
    if flag:
        print("Yes")
if __name__=="__main__":
    main()

Solution (Python):
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  A[i][0], A[i][1] = A[i][1], A[i][0]
A.sort()
S = 0
p = "Yes"
for i in range(N):
  S += A[i][1]
  if S > A[i][0]:
    p = "No"
    break
print(p)

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

time = 0
for task in ab:
    time += task[0]
    if time <= task[1]:
        
        continue
    else:
        print('No')
        exit()
print('Yes')

Solution (Python):
N=int(input())
AB={}
B=[]
base=0
answer="Yes"

for i in range(N):
    a,b=map(int,input().split())
    if b not in AB.keys():
        AB[b]=a
        B.append(b)
    else:
        AB[b]+=a
        
B=sorted(B)

for j in B:
    base+=AB[j]
    
    if base>j:
        answer="No"

print(answer)

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

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

import sys
work = 0

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

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

t = 0
ans = "Yes"

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

print(ans)

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

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

t = 0
ans = "Yes"

for i in range(N):
    a = task[i][0]
    b = task[i][1]
    t += a
    if t > b:
        ans = "No"
        break

print(ans)

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

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

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

jobs = sorted(jobs, key = lambda x: [x[1],-x[0]])
t = 0
ret = 'Yes'
for j in jobs:
	t += j[0]
	if t > j[1]:
		ret = 'No'
		break

print(ret)

Solution (Python):
n = int(input())
jobs = []
for _ in range(n):
    jobs.append(list(map(int, input().split())))
    
jobs.sort(key=lambda x:x[1]) 
time = 0
result = 'Yes'

for job in jobs:
    time += job[0]
    if(time > job[1]):
        result = 'No'
        break
print(result)

Solution (Python):



def main():
  n = int(input())
  AB = sorted([tuple(map(int, input().strip().split())) for _ in range(n)], key=lambda x:x[1])
  time = 0
  for a, b in AB:
    time += a
    if time > b:
      print('No')
      return
  print('Yes')

if __name__=='__main__':
  main()

Solution (Python):
N = int(input())
BAs = []
for n in range(N):
    A, B = [int(s) for s in input().split(' ')]
    BAs.append((B, A))
BAs.sort()
time = 0
count = 0
for B, A in BAs:
    time += A
    if time > B:
        break
    else:
        count += 1
if count == N:
    print('Yes')
else:
    print('No')

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

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

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

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

print(result)

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

Solution (Python):
def ok(ab):
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            return False
    return True

n = int(input())
print('Yes' if ok(sorted([list(map(int, input().split())) for _ in range(n)], key=lambda ab: ab[1])) else 'No')

Solution (Python):
import sys
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key= lambda x:x[1])
time = 0
for i in ab:
    time += i[0]
    if time <= i[1]:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

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

for i in range(n):
    if total+work[i][0] > work[i][1]:
        cnt += 1
        break
    else:
        total += work[i][0]

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

Solution (Python):
import numpy as np

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

timing = 0
is_safe = True
for item in works[(works[:,1].argsort(0))]:
    time, limit = item
    timing += time
    if timing > limit:
        is_safe = False
        break
print("Yes" if is_safe else "No")

Solution (Python):
from operator import itemgetter
n = int(input())
lis =sorted([list(map(int,input().split())) for _ in range(n)], key = itemgetter(1))
t = 0
ans = "Yes"
for i in lis:
    t += i[0]
    if t > i[1]:
        ans = "No"
print(ans)

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

Solution (Python):


import sys
from operator import itemgetter
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N = read_a_int()
AB = read_tuple(N)
AB.sort(key=itemgetter(1))
jikoku = 0
for a, b in AB:
    jikoku += a
    if jikoku > b:
        print('No')
        exit()
print('Yes')

Solution (Python):


import sys
from operator import itemgetter
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N = read_a_int()
AB = read_tuple(N)
AB.sort(key=itemgetter(1))
jikoku = 0
for a, b in AB:
    jikoku += a
    if jikoku > b:
        print('No')
        exit()
print('Yes')

Solution (Python):
n = int(input())
w = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
agg = 0
for c, t in w:
    agg += c
    if t < agg:
        print("No")
        exit()
print("Yes")

Solution (Python):
N = int(input())
d = {}
total = 0
for _ in range(N):
    a, b = map(int, input().split())
    d[b] = d.get(b, 0) + a
for t, c in sorted(d.items()):
    total += c
    if total > t:
        print("No")
        exit()
print("Yes")

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

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


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


remain_time = work[0][1]
in_time = True

for i in range(N):
  
  remain_time = min(work[i][1], remain_time) - work[i][0]
  
  
  if remain_time < 0:
    in_time = False
    break

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

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce

import heapq







def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n = getInputInt()
data = getSomeInputListInt(n)

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

lim = sys.maxsize
flg = True

for d in data_sorted:
    if lim > d[1]:
        lim = d[1]
    lim -= d[0]

    if lim<0:
        flg = False
        break

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