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())
W=[]
for i in range(N):
    W.append(list(map(int,input().split())))

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

sum=0

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

print("Yes")

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

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

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

cnt = 0
for i in range(N):
    temp = X[i][1]
    cnt += X[i][0]
    if temp < cnt:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

if(judge == 0): print('No')
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])
work_time = 0

for ab in AB:
  deadline = ab[1]
  work_time += ab[0]
  if deadline < work_time:
    print("No")
    exit()
print("Yes")

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

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

ans = 0

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

print('Yes')

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

l=[[0,0] for _ in range(n)]
for i in range(n):
    l[i][1],l[i][0]=map(int,input().split())
l.sort()
c=0
for i in range(n):
    c+=l[i][1]
    if l[i][0]<c:
        print('No')
        break
else:
    print('Yes')

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

AB.sort(key=lambda x:x[1])
now = 0
ans = "Yes"
for i in range(N):
    now += AB[i][0]
    if now > AB[i][1]:
        ans = "No"
        break
print(ans)

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

jobs = sorted(jobs, key = lambda x:x[1])
now = 0
for time, deadline in jobs:
    now += time
    if now > deadline:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from operator import itemgetter

lst=[]
n=int(input())
for _ in range(n):
    lst.append(list(map(int,input().split())))
lst.sort(key=itemgetter(1))

t=0
for a,b in lst:
    t +=a
    if t>b:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]
a.sort(key=lambda x: x[1], reverse=True)
b=a[0][1]
for i in a:
    b = min(b, i[1]) - i[0]
if b >= 0:
    print('Yes')
else:
    print("No")

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

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

k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    
    if k>ab[t][1]:
        answer=answer*0
if answer==1:
    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

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

print('Yes')

Solution (Python):
from sys import stdin, exit
N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
AB.sort(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())
data=[]
for i in range(n):
    a,b=map(int,input().split())
    data.append([b,a])
data.sort()
time=0
for i in range(n):
    time+=data[i][1]
    if time>data[i][0]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = sorted(LIR(n), key=lambda x:x[1])
ret = 0
for i in range(n):
    ret += L[i][0]
    if ret > L[i][1]:
        print('No')
        break
else:
    print('Yes')

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

Solution (Python):
import sys
N = int(input())
ABs = [list(map(int,input().split())) for _ in range(N)]
ABs.sort(key=lambda x: x[1]) 
time = 0
for i in range(N):
    time += ABs[i][0] 
    if time > ABs[i][1]:
        print('No')
        sys.exit()


print('Yes')

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

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


s = sorted(range(len(b)), key=lambda k: b[k])
fl = 0
time = 0
for si in s:
    time += a[si]
    if time > b[si]:
        fl = 1

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

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

n = int(input())

a_list = []
b_list = []
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))

    a_list.append(tmp_a)
    b_list.append(tmp_b)

z = zip(b_list, a_list)
z = sorted(z)
b_list, a_list = zip(*z)

sum_t = 0

flag = True
for a, b in zip(a_list, b_list):
    sum_t += a

    if sum_t > b:
        flag = False
        break

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

Solution (Python):
import sys
import bisect
import numpy as np
input = sys.stdin.readline
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=[int(x) for x in input().split()]
matrix = np.vstack((np.array(A),np.array(B)))
matrix = matrix[:, np.argsort(matrix[1])]
time=0
capacity=0
for a,b in zip(matrix[0],matrix[1]):
    capacity += (b-time) - a
    time = b
    if capacity <0:
        print('No')
        sys.exit()
    
print('Yes')

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

Solution (Python):
import heapq as hq

n = int(input())

list_A = []
list_B = []
h = []
for i in range(n):
    a, b = map(int, input().split())
    hq.heappush(h, [b, a])

time = 0
for _ in range(n):
    b, a = hq.heappop(h)
    time += a
    if b < time:
        print("No")
        exit()

print("Yes")

Solution (Python):
import heapq
import sys
N=int(input())
BA=[]
for i in range(N):
  a,b=map(int,input().split())
  heapq.heappush(BA,[b,a])
time=0
while BA!=[]:
  v=heapq.heappop(BA)
  b1,a1=v[0],v[1]
  time+=a1
  if time>b1:
    print('No')
    sys.exit()   
print('Yes')

Solution (Python):
import heapq as hq

N = int(input())
AB = []

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

t = 0
while AB:
    b, a = hq.heappop(AB)
    t += a

    if t > b:
        print('No')
        exit()
print('Yes')

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

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


def solve():
    t = 0
    for w in work:
        t += w[0]
        if t > w[1]:
            return False

    return True


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

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

current = 0

flag = True
for i in range(n):
  if (current + a[i]) > b[i]:
    flag = False
    break
  else:
    current += a[i]
  

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

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

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

Solution (Python):
from collections import defaultdict

N = int(input())
dict = defaultdict(list)
for _ in range(N):
    a, b = [int(x) for x in input().split()]
    dict[b].append(a)

total = 0
for k, v in sorted(dict.items()):
    total += sum(v)
    if k < total:
        print("No")
        exit()


print("Yes")

Solution (Python):
n = int(input())
Work = [list(map(int,input().split())) for i in range(n)]
Work = sorted(Work,key=lambda x: x[1])+[[0,0]]
time = Work[0][1]
for i in range(n):
  if Work[i][0] <= time:
    time -= Work[i][0]
    time += Work[i+1][1]-Work[i][1]
  else:
    print('No')
    exit()
print('Yes')

Solution (Python):


class Work():
    """ 仕事クラス """
    def __init__(self, a, b):
        self.need_time = a  
        self.deadline = b   


def solve():
    N = int(input())

    works = []  
    for _ in range(N):
        a, b = list(map(int, input().split()))
        works.append(Work(a, b))
    works.sort(key=lambda x: x.deadline)  

    
    now_time = 0  
    for i in range(N):
        now_time += works[i].need_time
        if now_time > works[i].deadline:
            print("No")
            return
    print("Yes")



if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
all = []
for i in range(N):
  tmp = []
  a,b = input().split()
  tmp.append(int(b))
  tmp.append(int(a))
  all.append(tmp)

all_sort = sorted(all)
ruikei = 0
judge = 'Yes'
for item in all_sort:
  ruikei += item[1]
  if ruikei > item[0]:
    judge = 'No'
    break;

print(judge)

Solution (Python):

import sys

class Work():

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


def solve():
    N = int(input())

    works = []
    for _ in range(N):
        a, b = list(map(int, sys.stdin.readline().split()))
        works.append(Work(a, b))
    works.sort(key=lambda x: x.deadline)  

    
    now_time = 0  
    for i in range(N):
        now_time += works[i].need_time
        if now_time > works[i].deadline:
            print("No")
            return
    print("Yes")



if __name__ == "__main__":
    solve()

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

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

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

C = [0]*len(AB)
C[0] = AB[0][0]
for i in range(1,len(AB)):
    C[i] += AB[i][0] + C[i-1]

ans = 1
for i in range(len(AB)):
    if AB[i][1] < C[i]:
        ans = 0

print('YNeos'[ans==0::2])

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

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

def solve():
  current_time = 0
  for work in sorted(AB, key=lambda x: x[1]):
    current_time += work[0]
    if current_time <= work[1]:
      pass
    else:
      return False
  return True

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

Solution (Python):
import sys

n = int(sys.stdin.readline())
jobs = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)] 

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

def solve(jobs):
	total = 0
	for time, deadline in jobs:
		total += time
		if total >  deadline:
			return False
	return True
print("Yes" if solve(jobs) else "No")

Solution (Python):
from operator import itemgetter

n = int(input())
a = []
res = ('Yes')
for i in range(n):
    a.append(list(map(int,input().split())))

a.sort(key=itemgetter(1))
suma = 0
for i in range(0,n):
    suma += a[i][0]
    if suma > a[i][1]:
        res = ('No')
        break


print(res)

Solution (Python):
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
AB.sort(key = lambda x:x[1])
s = 0
for ab in AB:
  s += ab[0]
  if s <= ab[1]:
    pass
  else:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
from operator import itemgetter


def solve(string):
    n, *ab = map(int, open(0).read().split())
    ab = sorted(zip(*[iter(ab)] * 2), key=itemgetter(1))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    print(solve(""))

Solution (Python):

from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))
    for task, deadline in TD:  
        cur += task
        if cur > deadline:  
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab[::-1])] * 2))
    past = 0
    for b, a in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=itemgetter(1))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from itertools import accumulate


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])
    a = [a for a, b in ab]
    b = [b for a, b in ab]
    *a, = accumulate(a)
    return "No" if any([_a > _b for _a, _b in zip(a, b)]) else "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: (x[1], x[0]))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab.sort(key=lambda p:p[1])
    t = 0
    for a,b in ab:
        t += a
        if t > b:
            print("No")
            break
    else:
        print("Yes")
if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate as acc
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    T, D = zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))
    flg = all(t <= d for t, d in zip(acc(T), D))  
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate as acc
from operator import itemgetter as gt


def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=gt(1))
    T, D = zip(*A)  
    
    flg = all(t <= d for t, d in zip(acc(T), D))
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Solution (Python):

from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))
    for task, deadline in TD:  
        cur += task
        if cur > deadline:  
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):

from itertools import accumulate
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    T, D = zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))
    T = list(accumulate(T))
    flg = all(t <= d for t, d in zip(T, D))  
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

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

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

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

lst.sort(key=lambda x: x[1])
sum_time = 0
for time,limitation in lst:
    sum_time+=time
    if sum_time<=limitation:pass
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
n = int(input())
d_line = []
for i in range(n):
    a, b = map(int, input().split())
    d_line.append([a, b])
d_line.sort(key = lambda x:-x[1])
time = d_line[0][1] - d_line[0][0]
for i, j in d_line[1:]:
    time = min(time,j)
    if time - i < 0:
        print('No')
        exit()
    time -= i
print('Yes' if time >= 0 else 'No')

Solution (Python):
n = int(input())
l = []
c = 0
d = 0
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l = sorted(l)


for i in range(0,n):
    if l[i][0] < d + l[i][1]:
        c = 1
        break
    else:
        d = d+ l[i][1]
        continue
if c == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
from collections import deque
import sys
n = int(input())
q = [None]*n
for i in range(n):
    q[i] = tuple(map(int, input().split()))
q = sorted(q, key = lambda x: x[1])
q = deque(reversed(q))
job = q.popleft()
day = job[1] - job[0]
if n == 1:
    if day >= 0:
        print("Yes")
    else:
        print("No")
    sys.exit()

while q:
    job = q.popleft()
    if job[1] < day:
        day = job[1] - job[0]
    else:
        day -= job[0]
    if day < 0:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
n = int(input())
ab=sorted([list(map(int,input().split())) for i in range(n)],key = lambda x:x[1])
s=[0]
for i in range(n):
    s.append(s[i]+ab[i][0])
if all(s[i+1] <= ab[i][1] for i in range(n)):
    print('Yes')
else:
    print('No')

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


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


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

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

n=int(input())
ab=[[int(i) for i in input().split()] for j in range(n)]
ab=sorted(ab,key=lambda x:x[1])

w=0
t=0
ans='Yes'
for a,b in ab:
    w+=a
    if b<w:
        ans='No'
    
print(ans)

Solution (Python):



n=int(input())
ab=[[int(i) for i in input().split()] for j in range(n)]
ab=sorted(ab,key=lambda x:x[1])

w=0
t=0
ans='Yes'
for a,b in ab:
    w+=a
    if b<w:
        ans='No'
    
print(ans)

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

N = int(input())
hq = []
for i in range(N):
    heappush(hq, tuple(reversed(list(map(int, input().split())))))
cnt = 0
for i in range(N):
    b, a = heappop(hq)
    cnt += a
    if cnt > b:
        print("No")
        sys.exit()
print("Yes")

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

q = []
for _ in range(N):
    val = list(map(int, input().split()))
    
    q.append(val)

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


cur = 0
for assign, limit in q:
    cur += assign
    if limit < cur:
        print("No")
        exit()

print("Yes")

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


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

Solution (Python):
import numpy as np
N=int(input())
a=[]
b=[]
xa=[]
xb=[]
y=[]
for i in range (0,N):
    c,d=(int(x) for x in input().split(" "))
    xa.append(c)
    xb.append(d)
     
z=np.argsort(xb)

for i in range (0,N):
    a.append(xa[z[i]])
    b.append(xb[z[i]])
for i in range (0,N):
    if i==0:
      	y.append(a[0])
    else:
      	y.append(a[i]+y[i-1])
def check(i,a,b):
    if b[i]>=y[i]:
        return True
    else:
        return False
def final_check(a,b,N):
    for i in range (0,N):
        if check(i,a,b)==False:
            return "No"
    return "Yes"
print (final_check(a,b,N))

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

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

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]

    X.sort(key=lambda X:X[1])
    time = 0
    for i in range(N):
        time += X[i][0]
        if time > X[i][1]:
            print("No")
            exit()

    print("Yes")  

if __name__ == "__main__":
    main()

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

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

Solution (Python):
N = int(input())
AB = [[0]*2 for i in range(N)]

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

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

print("Yes")

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

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

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

time = 0
for a, b in task:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import sys
N = int(input())
dic_work = {}
for i in range(N):
    a = [int(i) for i in input().split()]
    dic_work[i] = a

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

time = 0
for i, dic in dic_work:
    time += dic[0]
    if time > dic[1]:
        print("No")
        sys.exit()
print("Yes")

Solution (Python):

n = int(input())
work = []
for _ in range(n):
  work.append(list(map(int,input().split())))
work.sort(key= lambda x:x[1])
a = 0
b = 0

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

Solution (Python):
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    jobs = [tuple(map(int, input().split())) for _ in range(N)]
    jobs.sort(key=lambda x: x[1])
    jobs = deque(jobs)

    cur_time = 0
    while jobs:
        job = jobs.popleft()
        if job[1] < cur_time + job[0]:
            print("No")
            return 0
        else:
            cur_time += job[0]
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
  n=int(input())
  a=[0]*n
  b=a[:]
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  b,a=zip(*sorted(zip(b,a)))
  t=0
  for (i,j) in zip(a,b):
    t+=i
    if t>j:
      print("No")
      return
  print("Yes")
main()

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
tasks = []
cnt = 0
for i in range(n):
    a,b = inpl()
    tasks.append([a,b,abs(a-b)])
tasks.sort(key=lambda x:x[1])

for task in tasks:
    cnt += task[0]
    if cnt > task[1]:
        print('No')
        break
else:
    print('Yes')

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

Solution (Python):
import sys
input = lambda: sys.stdin.readline()[:-1]
n=int(input())
data=[tuple(map(int,input().split())) for i in range(n)]
data.sort(key=lambda tup:tup[1])
time=0
for offer in data:
	time+=offer[0]
	if time > offer[1]:
		print('No')
		break
else:print('Yes')

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

task_list = []

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

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

current = 0

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

print("Yes")

Solution (Python):
from operator import itemgetter

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

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

Solution (Python):
N = int(input())
W = [[0, 0] for _ in range(N)]
for i in range(N):
  A, B = map(int, input().split())
  W[i] = [B, A]
W.sort()
t = 0
for b, a in W:
  if b < t + a:
    print('No')
    break
  t += a
else:
  print('Yes')

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

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

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

def ans(works):
    time = 0
    for work in works:
        time += work[0]
        if time > work[1]:
            print("No")
            return
    print("Yes")
    return

ans(works)

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):
    if t <= AB[i][1] - AB[i][0]: 
        t += AB[i][0]
        continue
    else:
        print('No')
        break
else:
    if t <= AB[N-1][1]:
        print('Yes')
    else:
        print('No')

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]) 
AB = sorted(AB, key=lambda x: x[1])
t = 0

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

Solution (Python):
n = int(input())
d = {}
for i in range(n):
	a, b = map(int, input().split())
	if b in d:
		d[b].append(a)
	else:
		d[b] = [a]
dk = sorted(d)
t, o = 0, "Yes"
for k in dk:
	if t+sum(d[k]) > k:
		o = "No"
		break
	t += sum(d[k])
print(o)

Solution (Python):
n = int(input())
c = []
for i in range(n):
    a,b = map(int,input().split())
    c.append((b,a))
c.sort()
time = 0
f = True
for d,t in c:
    time+=t
    if time>d:
        f = False
        break
if f:
    print('Yes')
else:
    print('No')