Problem:
 Score: 400 points    Problem Statement  Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0 . Kizahashi has N jobs numbered 1 to N .  It takes A_i units of time for Kizahashi to complete Job i . The deadline for Job i is time B_i , and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print Yes ; if he cannot, print No .      Constraints   All values in input are integers.  1 \leq N \leq 2 \times 10^5  1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)         Input  Input is given from Standard Input in the following format:  N  A_1  B_1  .  .  .  A_N  B_N       Output  If Kizahashi can complete all the jobs in time, print Yes ; if he cannot, print No .        Sample Input 1 5
2 4
1 9
1 8
4 9
3 12      Sample Output 1 Yes  He can complete all the jobs in time by, for example, doing them in the following order:   Do Job 2 from time 0 to 1 .  Do Job 1 from time 1 to 3 .  Do Job 4 from time 3 to 7 .  Do Job 3 from time 7 to 8 .  Do Job 5 from time 8 to 11 .   Note that it is fine to complete Job 3 exactly at the deadline, time 8 .       Sample Input 2 3
334 1000
334 1000
334 1000      Sample Output 2 No  He cannot complete all the jobs in time, no matter what order he does them in.       Sample Input 3 30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720      Sample Output 3 Yes

Solution (Python):

from operator import itemgetter 
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):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter 
def main():
    N = int(readline())
    tasks = []
    for _ in range(N):
        a, b = map(int, readline().split())
        tasks.append((a, b))
    tasks.sort(key=itemgetter(1))
    time = 0
    for a, b in tasks:
        time += a
        if time > b:
            print('No')
            return  
    print('Yes')
if __name__ == '__main__':
    main()

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

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

C = list(zip(A,B))
C = sorted(C, key=lambda x:x[1])

time = 0
for a,b in C:
    time = time + a
    if time<=b:
        continue
    print("No")
    exit()
print("Yes")

Solution (Python):
def main():
    N = int(input())
    tasks = list()
    for _ in range(N):
        A, B = list(map(int, input().split(' ')))
        tasks.append((B, A))
    tasks.sort()
    current = 0
    for t in tasks:
        dead_line_time, required_time = t
        if current + required_time > dead_line_time:
            print('No')
            exit(0)
        current += required_time
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = sorted(list(list(map(int,input().split())) for _ in range(n)), key=lambda x:x[1])
t = 0
amari = 0
for a,b in l:
  
  if b-t>=a:
    amari += (b-t)-a
    t = b
  else:
    if amari>=a-(b-t):
      amari -= a-(b-t)
      t = b
    else:
      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
cnt=0
for i in range(n):
    time+=l[i][1]
    if time>l[i][0]:
        print("No")
        break
    else:
        cnt+=1
if cnt==n:
    print("Yes")

Solution (Python):

import sys
N=int(sys.stdin.readline().strip())
A=[]
for _ in range(N):
    time_req,end=map(int, sys.stdin.readline().split()) 
    A.append((end,time_req))
A.sort()

cur=0   

for end,time_req in A:
    cur+=time_req
    if cur<=end:    
        pass
    else:           
        print "No"
        quit()
else:
    print "Yes"

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans=0
t=0
for i in range(N):
 t+=lst[i][0]
 if t>lst[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Solution (Python):
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans=0
t=0
for i in range(N):
 t+=lst[i][0]
 if t>lst[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Solution (Python):
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2

 left = arr[:mid]
 right = arr[mid:]

 left = merge_sort(left)
 right = merge_sort(right)

 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0

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


 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][0]
 if t>lsta[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Solution (Python):
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2

 left = arr[:mid]
 right = arr[mid:]

 left = merge_sort(left)
 right = merge_sort(right)

 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0

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


 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
for i in range(N):
 A,B= map(int,input().split())
 lst[i]=[B,A]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][1]
 if t>lsta[i][0]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Solution (Python):
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2

 left = arr[:mid]
 right = arr[mid:]

 left = merge_sort(left)
 right = merge_sort(right)

 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0

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


 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
for i in range(N):
 A,B= map(int,input().split())
 lst[i]=[B,A]
lsta=merge_sort(lst)
ans=0
t=0
for i in range(N):
 t+=lsta[i][1]
 if t>lsta[i][0]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

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

A = []

for i in range(N):
    A.append((data[i][1],data[i][0]))

A = sorted(A)

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

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

A = []

for i in range(N):
    A.append((data[i][1],data[i][0]))

A = sorted(A)

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

Solution (Python):
n = int(input())
l = [[0,0]] * n
for i in range(n):
    A,B = map(int,input().split())
    l[i] = [A,B]
l = sorted(l,key=lambda x:x[1])

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

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

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

C = zip(B, A)
C = sorted(C)
B, A = zip(*C)

ans = 1
t = 0
for i, j in zip(A, B):
    t += i
    if t <= j:
        continue
    else:
        print("No")
        ans = 0
        break
if ans:
    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

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

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

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

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

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

C = zip(B, A)
C = sorted(C)
B, A = zip(*C)

ans = 1
t = 0
for i, j in zip(A, B):
    t += i
    if t <= j:
        continue
    else:
        print("No")
        ans = 0
        break
if ans:
    print("Yes")

Solution (Python):
n = int(input())
li = []
x = 0

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

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

print("Yes")

Solution (Python):
N = int(input())
works = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])
result = True
cnt = 0
for a, b in works:
    cnt += a
    if cnt > b:
        result = False
        break

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

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

Solution (Python):
from operator import itemgetter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,task):
    t = 0
    task = sorted(task, key=itemgetter(1))
    for item in task:
        t += item[0]
        if item[1] < t:
            return "No"
    return "Yes"

n = ii()
task = mix(n)
print(main(n,task))

Solution (Python):
'''
ABC 131 D:Megalomania
Accepted    　:Yes
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :9分
WAの回数　     :0回
合計時間　　  　:9分
'''
import sys
input = sys.stdin.readline

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer(N:int,dic:dict) -> str:
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def main():
   N = int(input())
   dic = {}
   
   
   for _ in range(N):
      a,b = map(int,input().split())
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
      
      
   print(modelAnswer(N,dic))
if __name__ == '__main__':
   main()

Solution (Python):
'''
ABC 131 D:Megalomania
Accepted    　:Yes
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :9分
WAの回数　     :0回
合計時間　　  　:9分
'''

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer(N:int,dic:dict) -> str:
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def main():
   N = int(input())
   dic = {}
   
   
   for _ in range(N):
      a,b = map(int,input().split())
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
      
      
   print(modelAnswer(N,dic))
if __name__ == '__main__':
   main()

Solution (Python):

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   A = []
   B = []
   for _ in range(N):
      a,b = map(int,input().split())
      A.append(a)
      B.append(b)
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

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

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

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

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

def main():
    N = int(readline())
    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
        
    print('Yes')

if __name__ == '__main__':
    main()

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

def main():
    N = int(readline())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
        
    print('Yes')

if __name__ == '__main__':
    main()

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

def main():
    N = int(readline())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        if t + a > b:
            print('No')
            return
        t += a
    
    print('Yes')

if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import defaultdict

n=int(input())

a=defaultdict(int)
b=defaultdict(int)


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


bb=sorted(b.items(),key=lambda x:x[1])

sum=0
for k,v in bb:
    sum += a[k]
    if sum > v:print('No');exit()

print('Yes')

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

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

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

print("Yes")

Solution (Python):
















N = int(input())
arrA = [list(map(int,input().split())) for _ in range(N)]
arrA.sort(key = lambda x:x[1])
num = 0
for arr in arrA:
    num += arr[0]
    if num > arr[1]:
        print("No")
        exit()

print("Yes")

Solution (Python):
n = int(input())
work_ls = [0] * n
for i in range(n):
    a,b = map(int,input().split())
    work_ls[i] = [a,b]
work_ls.sort(key = lambda x:x[1])
time = 0
res = 'Yes'
for cost, dline in work_ls:
    time += cost
    if time > dline:
        res = 'No'
print(res)

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

Solution (Python):
n = int(input())
arr = []
tmp = 0
flg = 0
for i in range(n):
  a,b = map(int, input().split())
  arr.append([b,a])
arr.sort()
for i in range(n):
  tmp += arr[i][1]
  if tmp > arr[i][0]:
    flg = 1
if flg == 0:
  print('Yes')
else:
  print('No')

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

Solution (Python):

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

from operator import itemgetter
AB = sorted(AB, key=itemgetter(1))

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

Solution (Python):

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

from operator import itemgetter
AB = sorted(AB, key=itemgetter(1))

rt = 'Yes'
X = []
val = 0
for i in range(N):
    val += AB[i][0]
    X.append( [val, AB[i][1]] )
    if val > AB[i][1] :
        rt = 'No'
        break
print(rt)

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

Solution (Python):
n=int(input())
A=[[0,0] for i in range(n)]
for i in range(n):
  A[i][1],A[i][0]=map(int,input().split())
  
A.sort()
time=0
flg=True
for i in range(n):
  time+=A[i][1]
  if time>A[i][0]:
    flg=False
    
if flg:
  print('Yes')
else:
  print('No')

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

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

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

now = 0 
for ab in AB:
    now += ab[0]
    if now > ab[1]:
        print("No")
        exit()
print("Yes")

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

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

time = 0
for a, b in works:
    time += a
    if b < time:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 







n = int(input())
now = 0
s = {}
for _ in range(n):
    a, b = map(int, input().split())
    if b in s:
        s[b] = s[b] + a
    else:
        s[b] = a
s = sorted(s.items())
for x in s:
    now += x[1]
    if now > x[0]:
        print('No')
        sys.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])

time=0
for i in range(N):
  time+=AB[i][0]
  if time<=AB[i][1]:
    continue
  else:
    print("No")
    exit()
print("Yes")

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
flag = True
sortedab = sorted(ab, key=lambda x:x[1])
cleartime = [0]*n
cleartime[0] = sortedab[0][0]
if cleartime[0] > sortedab[0][1]:
    flag = False
else:
    for i in range(1, n):
        cleartime[i] = cleartime[i-1] + sortedab[i][0]
        if cleartime[i] <= sortedab[i][1]:
            continue
        else:
            flag = False
            break
if flag:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
n = int(input())
l = [[0, 0] for _ in range(n)]
ans = "Yes"
for i in range(n):
    a, b = map(int, input().split())
    l[i][0] = b
    l[i][1] = a
l.sort()
t = 0
for i in range(n):
    t += l[i][1]
    if t > l[i][0]:
        ans = "No"
        break
print(ans)

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

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

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

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

cnt = 0
for a, b in AB:
    if cnt + a <= b:
        cnt += a
    else:
        print("No")
        exit()
print("Yes")

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

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

cnt = 0
for a, b in AB:
    if cnt + a <= b:
        cnt += a
    else:
        print("No")
        exit()
print("Yes")

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

def main():
    N = int(input())
    AB = sorted([[int(_) for _ in input().split()] for __ in range(N)], key=lambda x:x[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            break
    else:
        print('Yes')

    return

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def D():
    n = int(input())
    t = [list(map(int, input().split()))[::-1] for _ in range(n)]
    t = sorted(t)
    time, result = 0, "Yes"
    for b, a in t:
        time += a
        if b < time:
            result = "No"
            break
    print(result)        
D()

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

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

print("Yes")

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

dic = {}
B = []

for i in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if '{}'.format(b) in dic:
        dic['{}'.format(b)] += a
    else:
        dic['{}'.format(b)] = a

Bs = sorted(list(set(B)))

time = 0

for i, num in enumerate(Bs):
    time += dic['{}'.format(num)]
    if num < time:
        print('No')
        break

    if i == len(Bs)-1:
        print('Yes')

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

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

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


def main():
    N = int(input())
    work = []  
    for _ in range(N):
        a, b = map(int, input().split())
        work.append((b, -a))
    work.sort()

    now = 0
    for b, a in work:
        now = now - a
        if now > b:
            return "No"
    return "Yes"


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

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 a, b in ab:
    time += a
    if time > b:
        ans = "No"

print(ans)

Solution (Python):


import sys



















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    task = []
    for _ in range(n):
        a, b = mi()
        task.append([a, b])
    task.sort(key=lambda x: x[1])
    t = max(task, key=lambda x: x[1])[1]
    while task:
        required_slot, end = task.pop()
        
        if t > end:
            t = end
        t -= required_slot
    print('No') if t < 0 else print('Yes')



if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L = []
for i in range(N):
    A,B = map(int,input().split())
    L.append([B,A])
L = sorted(L)
t = 0
for i in range(N):
    t += L[i][1]
    if t > L[i][0]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from operator import itemgetter
N = int(input())
A = [None] * N
for i in range(N):
  A[i] = list(map(int,input().split()))


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

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

Solution (Python):
from operator import itemgetter
N = int(input())
A = [None] * N
for i in range(N):
  A[i] = list(map(int,input().split()))

s = sorted(A, key=itemgetter(0),reverse=True)
t = sorted(s, key=itemgetter(1))

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

Solution (Python):
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
time = 0
ab = sorted(ab, key=lambda x:x[1])
for a, b in ab:
  time += a
  if time <= b:
    pass
  else:
    print('No')
    exit()
print('Yes')

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab, key=lambda AB: AB[1])
ans = 'Yes'
t = 0
for AB in sorted_ab:
  t += AB[0]
  if t > AB[1]:
    ans = 'No'
    break

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline









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

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

ans = "Yes"
total = 0
for a,b in AB:
    total += a
    if total > b:
        ans = "No"
        break

print(ans)

Solution (Python):
from operator import itemgetter

n = int(input())

j_list = []
for _ in range(n):
    a, b = [int(x) for x in input().split()]
    j_list.append((a, b))
j_list.sort(key=itemgetter(1))

ans = "Yes"
t = 0
for a, b in j_list:
    t += a
    if t > b:
        ans = "No"
        break
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 = 0
flg = True
for i in range(n):
    time += work[i][0]
    if time > work[i][1]:
        flg = False
        break
        
if flg:
    print('Yes')
    
else:
    print('No')

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N = int(input())
li = [0]*N
for i in range(N):
    A,B = inputlist()
    li[i] = [B,A]
li.sort()
suma = li[0][1]
if suma > li[0][0]:
    print("No")
    exit()
for i in range(1,N):
    suma += li[i][1]
    if suma > li[i][0]:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys
N = int(input())
work = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
work_soted = sorted(work, key=lambda x:(x[1], -x[0]))

bool = True
time = 0
for i in range(N):
    time += work_soted[i][0]
    if time > work_soted[i][1]:
        bool = False
        break
    
if bool:
    print('Yes')
else:
    print('No')

Solution (Python):
n = int(input())
l = []
ans = "Yes"
for i in range(n):
    a, b = map(int, input().split())
    l.append([b, a])
l.sort(reverse=True)
tmp = l[0][0]
for i in range(n):
    if tmp > l[i][0]:
        tmp = l[i][0]
    tmp -= l[i][1]
    if tmp < 0:
        ans = "No"
        break
print(ans)

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

ab = [[0]*2 for i in range(n)]

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

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

ws = 0

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

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

for i in range(n):
  sum+=a[i]
  if sum>b[i]:
    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])
t = 0
flag = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

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

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

ABs.sort()

t = 0
for tTo, tm in ABs:
    t += tm
    if tTo < t:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
n,*pl=map(int,open(0).read().split())
l=[[pl[i],pl[i+1]] for i in range(0,n*2,2)]
l.sort(key=lambda x:x[1])
t=0
p=True
for i,j in l:
    t+=i
    if t>j:
        p=False
        print('No')
        break
if p:
    print('Yes')

Solution (Python):
n=int(input())
l=list()
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:x[1])
t=0
p=True
for i,j in l:
    t+=i
    if t>j:
        p=False
        print('No')
        break
if p:
    print('Yes')

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