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 = []
for i in range(N):
    l = input().split()
    AB.append((int(l[0]), int(l[1])))

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


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

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

Solution (Python):
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    time = 0
    due = 0

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

solve()

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

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

memo = memo[np.argsort(memo[:,1])]

flag = True
s = 0
for i in range(N):
    s += memo[i,0]
    if memo[i,1]-s<0:
        flag = False
        break

if flag:
    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])

deth =0
time =0
ans = 0
for i in l:
    deth = i[1]
    time += i[0]
    if deth < time:
        print("No")
        ans += 1
        break
if ans == 0:
    print("Yes")

Solution (Python):
from functools import reduce
from operator import add

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

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

total = 0
f = True
for a, b in AB:
    total += a
    if total > b:
        f = False
        break

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

Solution (Python):
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)






N = int(input())

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

BA.sort()

c = 0
ans = True
for i in range(N):
    b, a = BA[i]
    c += a
    
    if c > b:
        ans = False
        break

if ans == True:
    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])
time = 0
flag = True
for i in range(N):
    time += ab[i][0]
    if time > ab[i][1]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Solution (Python):

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

Solution (Python):
def main():
    N = int(input())
    tasks = [tuple(map(int, input().split())) for _ in range(N)]
    tasks = sorted(tasks, key=lambda x: x[1])
    ct = 0
    for t in tasks:
        if ct+t[0] > t[1]:
            return False
        ct += t[0]
    return True

if __name__ == '__main__':
    if main():
        print("Yes")
    else:
        print("No")

Solution (Python):
def LI(): return list(map(int, input().split()))

n = int(input())
pair = []
for _ in range(n):
    _a, _b = LI()
    pair.append((_b, _a))

pair.sort()

acc = 0
last_b = 0
for b, a in pair:
    acc += (b - last_b) - a
    last_b = b

    if acc < 0:
        print('No')
        break
else:
    print('Yes')

Solution (Python):

from heapq import heappush, heappop

def solve():
    N = int(input())
    hq = []
    for i in range(N):
        A, B = map(int, input().split())
        heappush(hq, (B,A))

    time = 0
    cost = 0
    while hq:
        l, c = heappop(hq)
        if time == l:
            cost += c
        else:
            time = l
            cost += c
        if cost > time:
            return 'No'
    return 'Yes'
if __name__ == '__main__':
    print(solve())

Solution (Python):
from operator import itemgetter

def main():
    n = int(input())
    works =[]
    for i in range(n):
        works.append(tuple(map(int,input().split(" "))))
    sortworks = sorted(works, key=itemgetter(1))
    
    time = 0
    flag = True
    for i in sortworks:
        time += i[0]
        if time > i[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Solution (Python):

class Work:
    weight = 0
    deadline = 0
    
    def __init__(self, w, d):
        self.weight = w
        self.deadline = d
        
    def __lt__(self, other):
        return self.deadline < other.deadline
        
N = int(input())
works = []
for l in range(N):
    a,b = [int(i) for i in input().split()]
    works.append(Work(a,b))
    
works.sort()
keika = 0
ans = "Yes"
for i in range(len(works)):
    keika += works[i].weight
    if keika > works[i].deadline:
        ans = "No"
        break

print(ans)

Solution (Python):



def main():
    N = int(input())
    
    task = []
    for i in range(N):
        Ai, Bi = map(int, input().split())
        task.append([Ai, Bi])
    time = 0
    task.sort(key=lambda x: x[1])
    
    ans = True

    for i in range(N):
        Ai, Bi = task[i]
        time += Ai
        if time > Bi:
            ans = False
            break

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
l = []
for i in range(n):
    l += [list(map(int,input().split()))]
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())
works = []
for _ in range(n):
    a,b = map(int,input().split())
    works.append([a,b])
works = sorted(works,key=lambda x:x[1])
time = 0
flag = 0
for work in works:
    a,b = work
    time += a
    if time > b:
        flag = 1
        break

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

Solution (Python):
N = int(input())
l = [None]*N
for i in range(N):
    l[i] = [int(x) for x in input().split()]
new_list = sorted(l, key = lambda z:z[1])
total_time = 0
for i in range(N):
    total_time += new_list[i][0]
    if total_time > new_list[i][1]:
        print('No')
        exit()
else:
    print('Yes')

Solution (Python):
import sys

N = int(input())
worktime, deadline = [], []

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

union = sorted(zip(worktime, deadline), key=lambda x: x[1])
worktime, deadline = zip(*union)

current = 0
for i in range(N):
    if current + worktime[i] > deadline[i]:
        print("No")
        sys.exit()
    else:
        current += worktime[i]
        pass
print("Yes")

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

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

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

t = 0
for t_job, t_dead in AB:
    t += t_job
    if (t_dead < t):
        print('No')
        sys.exit()

print('Yes')

Solution (Python):

N = int(input())

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

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

now = 0
remain = 0

for job in sorted_jobs:
    cost = job[0]
    limit = job[1]

    remain += limit - now
    now = limit

    remain -= job[0]

    if remain < 0:
        print("No")
        exit()

print("Yes")

Solution (Python):
N = int(input())
BA = [[int(n) for n in input().split()][::-1] for _ in range(N)] 
BA = sorted(BA)
T = 0
for ba in BA:
    T += ba[1]
    if T > ba[0]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

import heapq


n = int(input())
q = []

for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(q, (b, a))

wk_time = 0
finished = True
for _ in range(n):
    b, a = heapq.heappop(q)
    wk_time += a
    if wk_time > b:
        finished = False
        break

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

Solution (Python):

from sys import stdin
import sys, fractions
import numpy as np

def main():
    n = int(stdin.readline().rstrip())
    matrix = [stdin.readline().rstrip().split() for _ in range(n)]
    matrix = np.array(matrix, dtype='int32')
    matrix = matrix[np.argsort(matrix[:,-1])]
    task_time = matrix[:,0]
    task_time_sum = np.cumsum(task_time)
    limited_time = matrix[:,-1]
    
    
    for x, y in zip(task_time_sum, limited_time):
        if x > y:
            return(0)
    
    return(1)
    
if __name__ == '__main__':
    ans = main()
    print('Yes' if ans==1 else 'No')

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

for i in range(N):
	a, b = (map(int, input().split()))
	A.append([a, b])
	
A = sorted(A, key = lambda x : x[1])
summ = 0
output = 'Yes'

for i in range(N):
	summ += A[i][0]
	if summ > A[i][1]:
		output = 'No'
		break
		
print(output)

Solution (Python):



import sys

N = int(input())

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

cumsum = 0
for i in range(N):
    cumsum += X[i][0]
    if X[i][1] < cumsum:
        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])
t=0
for a,b in ab:
    t+=a
    if t>b:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        N = int(input())
        AB = []
        for i in range(N):
            a, b = map(int, input().split())
            AB.append((a, b))
        AB = sorted(AB, key=lambda x: x[1])

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


if __name__ == '__main__':
    Solution().main()

Solution (Python):
import numpy as np
N=int(input())
A = [0]*N
B = [0]*N
for i in range(N):
  A[i],B[i] = map(int, input().split())
  
  
index = np.argsort(B)
Asort = [0]*N
Bsort = [0]*N
for i in range(N):
  Bsort[i] = B[index[i]]
  Asort[i] = A[index[i]]
  
flag = True
val = 0
for i in range(N):
  val = val+Asort[i]
  if val > Bsort[i]:
    flag = False
if flag==True:
  print('Yes')
else:
  print('No')

Solution (Python):
from operator import itemgetter, attrgetter

N = int(input())

pairs = []

for n in range(N):
  pairs.append(tuple(map(int, input().split())))

pairs = sorted(pairs, key=itemgetter(1))
  
t = 0

for p in pairs:
  t += p[0]
  if p[1] < t:
    print('No')
    exit(0)
    
print('Yes')

Solution (Python):
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    N = int_raw()
    BAs = []
    for i in range(N):
        A,B = ints_raw()
        BAs.append([B,A])
    BAs.sort()
    t = 0
    for BA in BAs:
        B,A = BA
        t+=A
        if B<t:
            return "No"
    return "Yes"


print(main())

Solution (Python):
def solve():
    BA = sorted(list(map(int, input().split()))[::-1] for _ in range(int(input())))
    cnt = 0
    for b, a in BA:
        if cnt + a <= b:
            cnt += a
        else:
            return "No"
    return "Yes"
print(solve())

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

print(ans)

Solution (Python):
N = input()

arr = []

for i in xrange(N):
    a,b = map(int,raw_input().split())
    arr.append([a,b])

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

time = 0
ans = 'Yes'


for i in xrange(N):
    time += arr[i][0]
    if arr[i][1]-time < 0:
        ans = 'No'
        break
    arr[i].append(time)





print ans

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

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    l.append({'cost': a, 'deadline': b})

def solve(list):
    list_sorted = sorted(list, key=lambda x:x['deadline'])

    t = 0
    for i in list_sorted:
        t = t + i['cost']
        if t > i['deadline']:
            return False

    return True


print('Yes' if solve(l) else 'No')

Solution (Python):

n = int(input())
dic = []
for i in range(n):
    a, b = list(map(int, input().split()))
    dic.append({'task': i, 'duration': a, 'due': b})
dicsort = sorted(dic, key = lambda x: (x['due'], x['duration']))
completed = 0
result = True
for i in dicsort:
    completed += i['duration']
    if completed > i['due']:
        result = False
        break
if result:
    print('Yes')
else:
    print('No')

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

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


if __name__=="__main__": main()

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

time = 0
for i in range(N):
    A[i], B[i]= map(int, input().split())
    if A[i] > B[i]:
        print('No')
        quit()

index = sorted(range(N), key=lambda k: B[k])
for ind in index:
    if time + A[ind] > B[ind]:
        print('No')
        quit()
    else:
        time += A[ind]
print('Yes')

Solution (Python):
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
SB = sorted(L, key=lambda x:x[1])
flg = 0
cnt = 0
for i in range(N):
    cnt += SB[i][0]
    if SB[i][1] < cnt:
        flg = 1
        break
if flg == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
import itertools as itr

n = int(input())
ab = []
for _ in range(n):
    ab.append(list(map(int, input().split())))
ab.sort(key=lambda x: x[1])
a = [x[0] for x in ab ]
b = [x[1] for x in ab ]
finished = list(itr.accumulate(a))
ans = 'Yes'
for i in range(n):
    if finished[i] > b[i]:
        ans = 'No'
        break
print(ans)

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

N = int(input())
A = [0]*N
work = 0
for i in range(N):
    A[i] = list(map(int, input().split()))
A.sort(key=itemgetter(0))
A.sort(key=itemgetter(1))

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

print('Yes')

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

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

line=[]

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

line.sort()

s=0
t=0

for i in range(n):
    t=line[i][0]
    s+=line[i][1]
    if s>t:
        print('No')
        break
    if i==n-1:
        print('Yes')

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a_b = [list(map(int, input().split())) for _ in range(N)]
a_b = sorted(a_b, key = lambda x: (x[1], x[0]))
sum_t = 0
flag = 0
for t, lim in a_b:
    sum_t += t
    if sum_t > lim:
        flag = 1
        break
if flag:
    print('No')
else:
    print('Yes')

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

Solution (Python):
import sys, heapq

def solve():
    input = sys.stdin.readline
    N = int(input())
    Q = []
    heapq.heapify(Q)
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(Q, (b, a))
    time = 0

    for i in range(N):
        b, a= heapq.heappop(Q)
        if time + a > b:
            print("No")
            break
        else:
            time += a

    else: print("Yes")



    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A, B = [], []
    for ix in range(N):
        a, b = LI()
        A.append(a)
        B.append((ix, b))
    B = sorted(B, key=lambda x: x[1])
    cur_t = 0
    ans = "Yes"
    for b in B:
        ix, b_dead = b
        cur_t += A[ix]
        if cur_t > b_dead:
            ans = "No"
            break
    print(ans)

main()

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

elapsed_time = 0
for AB in ABs:
    A = AB[0]
    B = AB[1]
    if elapsed_time + A > B:
        print('No')
        exit()
    elapsed_time += A

print('Yes')

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

total = 0
tf = True
for l in ls:
    total += l[0]
    if total > l[1]:
        tf = False
        break
if tf:
    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])

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

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

Solution (Python):
n = list(map(int, input().split()))
n = n[0]

ab=[]

for i in range(n):
    cd = list(map(int, input().split()))
    ab.append(cd)

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



le = 0

flag = "Yes"

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

Solution (Python):
import sys
from operator import itemgetter


def solve(tasks):
    tasks.sort(key=itemgetter(1))
    t = 0
    for a, b in tasks:
        t += a
        if t > b:
            return False
    return True


n = int(input())
tasks = [tuple(map(int, line.split())) for line in sys.stdin]
print('Yes' if solve(tasks) else 'No')

Solution (Python):
n = int(input())
ab_array = [[int(x) for x in input().split()] for x in range(n)]
ab_array = sorted(ab_array, key=lambda x: x[1])
time = 0
for a, b in ab_array:
    if b < a+time:
        print("No")
        exit()
    time += a
print("Yes")

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

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

time, i = task[0][0], 0
while time <= task[i][1]:
    i += 1
    if i >= N:  break
    time += task[i][0]

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

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

for _ in range(n):
    c,d = map(int,input().split())
    tasks.append([d,c])
tasks.sort()
maxday = tasks[-1][0]
worked = 0
for i in range(n):
    day = tasks[i][0]
    cost = tasks[i][1]
    if day - worked < cost :
        print("No")
        exit()
    else:
        worked += cost
print("Yes")

Solution (Python):
N = int(input())
works = list()
safe = True
for _ in range(N):
    works.append(list(map(int, input().split())))

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

for work in works:
    cumsum += work[0]
    if cumsum > work[1]:
        safe = False
        break

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

Solution (Python):


import sys
import math

N = int(input())

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


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

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


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


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


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

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

Solution (Python):
import sys
N = int(input())
arr = []
for i in range(N):
    a, b = map(int, input().split())
    arr.append([b, a])

arr = sorted(arr)

sum = 0
for i in range(N):
    sum += arr[i][1]
    if sum > arr[i][0]:
        print("No")
        sys.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])
worktime = 0
ndat = 0
for i in range(N):
    worktime += AB[i][0]
    if worktime > AB[i][1]:
        print('No')
        break
    ndat += 1
if ndat == N:
    print('Yes')

Solution (Python):
import sys

N = int(input())

AB = [0] * N

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

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

time = 0
for i in AB:
    A, B = i
    time += A
    if time > B:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):

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

d.sort(key=lambda x : x[1])
ret = "Yes"
cur_task = 0
for ab in d:
    cur_task+=ab[0]
    if cur_task > ab[1]:
        ret = "No"
        break
print(ret)

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

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


ok = True
time = 0
for i in range(N):
  b,a=wlist[i]
  time += a
  if time > b:
    ok = False
    break
    
if ok:
  print("Yes")
else:
  print("No")

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

t =0
for j in job:
    t += j[0]
    if t > j[1]:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
N = int(input())
itv = []
for i in range(N):
  itv.append(list(map(int, input().split())))
itv.sort(key=lambda x: x[1])
ans = 0
t = 0
for i in range(N):
  if (t <= itv[i][1]-itv[i][0]):
    ans += 1
    t += itv[i][0]
if ans == N:
  print ("Yes")
else:
  print ("No")

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

s=0
possible=True
for a, b in sorted(AB, key=lambda x:x[1]):
    s+=a
    if s>b:
        possible = False
        break

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

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

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

T=0
for e in x:
    T+=e[0]
    if e[1]<T:
        print("No")
        exit()
print("Yes")

Solution (Python):

def get_input():
    N = int(input())
    AB = [tuple(map(int,input().split(" "))) for i in range(N)]
    return N,AB

def solve(N,AB):
    sortedAB = sorted(AB,key=lambda x:x[1])
    sum_of_work = 0 
    flag = True  
    for a,b in sortedAB:
        sum_of_work += a 
        if sum_of_work > b :
            flag = False 
            break
    print("Yes" if flag else "No")




solve(*get_input())

Solution (Python):
def inpl(): return list(map(int, input().split()))
N = int(input())

A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = inpl()

T = sorted([(B[i], A[i]) for i in range(N)])

t = 0
for i in range(N):
    b, a = T[i]
    if b < t+a :
        print("No")
        break
    t += a
else:
    print("Yes")

Solution (Python):
N = int(input())
W = []
for _ in range(N):
  a, b = map(int, input().split())
  W.append([a, b])
s = 0 
for a, b in sorted(W, key=lambda x: x[1]):
  s += a
  if s > b:
    print('No')
    quit()
print('Yes')

Solution (Python):
import sys, fractions

readline = sys.stdin.readline

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

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

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

print('Yes')

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

AB = [(-1, -1)] * N

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

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


enable = True
now = 0

for a, b in AB:
    if (now + a) <= b:
        now += a
    else:
        enable = False
        break

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

Solution (Python):


N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

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

print(result)

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

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

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

tt = 0
flag = False
for tk in tasks:
    tt += tk[0]
    if tt > tk[1]:
        flag = True
        break

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

Solution (Python):

import sys
N = int(input())
ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append((b, a))
ab=sorted(ab, reverse = True)
time = ab[0][0]
flag = True
for i in range(N):
    b, a = ab[i]
    if ab[i][0]<time:
        time = b-a
    else:
        time -=a
    
if time>=0:
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
b=np.array([ab[i-1][1] if i>0 else 0 for i in range(n+1)])
ruisekiA=np.zeros(n+1)
for i in range(n):
    ruisekiA[i+1]=ruisekiA[i]+ab[i][0]



if len(ruisekiA[ruisekiA>b])==0:
    print('Yes')
else:
    print('No')

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

works = []

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

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

deadtime = works[-1][1]

t = 0
ok = True
for w in works:
    if t + w[0] <= w[1]:
        t += w[0]
    else:
        ok = False
        break


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

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd

YES = "Yes"  
NO = "No"  

def solve(N: int, A: "List[int]", B: "List[int]"):
    
    s = sorted([(b, i ) for i, (a, b) in enumerate(zip(A, B))])

    t = 0
    for _, i in s:
        a, b = A[i], B[i]
        t += a
        if b < t:
            return 'No'

    return 'Yes'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    result = solve(N, A, B)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
score = 0
flag = 1
n = int(input())
task = []
for i in range(n):
  task.append(list(map(int,input().split())))
t = sorted(task, key=lambda x:x[1])
for i in range(n):
  score += t[i][0]
  if score > t[i][1]:
    print('No')
    flag = 0
    break
if flag == 1:
  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])
now = 0
ans = 'Yes'

for i in range(N):
    now += AB[i][0]
    if now <= AB[i][1]:
        pass
    else:
        ans = 'No'

print(ans)

Solution (Python):

def main():
    buf = input()
    N = int(buf)
    BA = []
    for i in range(N):
        buf = input()
        buflist = buf.split()
        BA.append((int(buflist[1]), int(buflist[0])))
    BA.sort()
    elapsed = 0
    for x in BA:
        elapsed += x[1]
        if elapsed > x[0]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

Solution (Python):
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
time = 0
hoge = "Yes"
s = sorted(s, key=lambda s:s[1])
for i in s:
    time += i[0]
    if time > i[1]:
        hoge = "No" 
        break

print(hoge)

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


ab = sorted(ab, key=lambda x: x[1])
sumNeed = 0
for item in ab:
    sumNeed += item[0]
    if sumNeed > item[1]:
        print('No')
        exit()

print('Yes')

Solution (Python):
from operator import itemgetter
N = int(input())
AB = [[int(x) for x in input().split()] for i in range(N)]
AB = sorted(AB, key=itemgetter(1, 0))

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

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

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

time = 0
flag = 1
for d, t in lis:
    time += t
    if time > d:
        flag = 0
        
print(['No', 'Yes'][flag])