Buggy code:
import sys
N = int(input())
A, B = [], []
for _ in range(N):                                                                                                                                                                                          
    a, b = (int(x) for x in input().split())                                                                                                                                                                
    A.append(a)                                                                                                                                                                                             
    B.append(b)                                                                                                                                                                                             

B_ = sorted(B)
B_id = sorted(range(len(B)), key=lambda k:B[k])

time = 0
for i in range(N):                                                                                                                                                                                          
    time += A[B_id[i]]                                                                                                                                                                                      
    print(time)                                                                                                                                                                                             
    print(B_[i])                                                                                                                                                                                            
    if time > B_[i]:                                                                                                                                                                                        
        print('No')                                                                                                                                                                                         
        sys.exit()                                                                                                                                                                                          

print('Yes')


Fixed code:
import sys
N = int(input())
A, B = [], []
for _ in range(N):                                                                                                                                                                                          
    a, b = (int(x) for x in input().split())                                                                                                                                                                
    A.append(a)                                                                                                                                                                                             
    B.append(b)                                                                                                                                                                                             

B_ = sorted(B)
B_id = sorted(range(len(B)), key=lambda k:B[k])

time = 0
for i in range(N):                                                                                                                                                                                          
    time += A[B_id[i]]                                                                                                                                                                                      
    if time > B_[i]:                                                                                                                                                                                        
        print('No')                                                                                                                                                                                         
        sys.exit()                                                                                                                                                                                          

print('Yes')