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())
task = [list(map(int, input().split())) for i in range(N)]
task.sort(key=lambda x:x[1])
time = 0
for i in range(N):
  time += task[i][0]
  if time > task[i][1]:
    print("No")
    exit()
else:
  print("Yes")

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

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

t.sort(key=lambda x: (x[1], x[0]))

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

Solution (Python):


n = int(input())

jobs = []

for i in range(n):
    a, b = map(lambda x:int(x), input().split())
    jobs.append([b, a])
jobs.sort()

job_count = 0
pass_time = 0

for j in jobs:
    if pass_time + j[1] <= j[0]:
        job_count += 1
        pass_time += j[1]
    else:
        break

if job_count == n:
    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])

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

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

def main():
	n = int(input().strip())
	s = [[0] * 2 for _ in range(n)]
	for i in range(n):
		s[i][0], s[i][1] = map(int, input().strip().split())
	s2 = sorted(s, key=itemgetter(1))
	t = 0
	for item in s2:
		t += item[0]
		if t > item[1]:
			print('No')
			return
	print('Yes')

if __name__ == '__main__':
	main()

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

end = 0
for p,q in a:
    end += q
    if end > p:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys
from functools import cmp_to_key
n = int(input())
data = [[int(j) for j in input().split()] for i in range(n)]
t = 0
data.sort(key = cmp_to_key(lambda x, y: x[1] - y[1]))
for d in data:
  t += d[0]
  if t > d[1]:
    print('No')
    sys.exit()
print('Yes')

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

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

for i in range(n):
    time[i] = [time[i][1],time[i][0]]

time.sort()

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

print(ans)

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

l.sort()

sum_ = 0
for i in range(n):
  sum_ += l[i][1]
  if sum_ > l[i][0]:
    print('No')
    exit()
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])

count = 0
can = True
for i in range(n):
    count = count + ab[i][0]
    if count > ab[i][1]:
        print("No")
        can = False
        break

if can:
    print("Yes")

Solution (Python):
N = int( input() )
n = []
for i in range(N):
	n.append(input().split())
	n[i][0] = int(n[i][0])
	n[i][1] = int(n[i][1])

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

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

Solution (Python):

import sys

n=int(raw_input())
ab=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 ab.append([a,b])
ab=sorted(ab,key=lambda x:x[1])
acm=0
for i in xrange(n):
 acm+=ab[i][0]
 if acm>ab[i][1]:
  print 'No'
  sys.exit()
print 'Yes'

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

Solution (Python):
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

def main():
	n=int(input())
	l=[];t=0;flg=0
	for i in range(1,n+1,1):
		a,b=map(int,input().split())
		c=(b,a)
		l.append(c)
	l.sort()
	flag = True
	for x,y in l:
		t+=y
		if t>x:
			flag = False
	if flag:print("Yes")
	else:print("No")

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

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

Solution (Python):
n = int(input())
ba = []
for i in range(n):
    a, b = (int(j) for j in input().split())
    tmp = []
    tmp.append(b)
    tmp.append(a)
    ba.append(tmp)
ba.sort()

s = 0
f = True
for i in range(n):
    s += ba[i][1]
    if ba[i][0] < s:
        f = False
        break
if f:
    print("Yes")
else:
    print("No")

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

inputs.sort(key=lambda x: x[1])
time = 0
for item in inputs:
    time += item[0]
    if time > item[1]:
        print('No')
        break
else:
    print('Yes')

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

l.sort(key=lambda x: x[1])
time = 0
for w, t in l:
    time += w
    if t < time:
        print("No")
        exit()
else:
    print("Yes")

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

l.sort(key=lambda x: x[1])
time = 0
for w, t in l:
    time += w
    if t < time:
        print("No")
        exit()
else:
    print("Yes")

Solution (Python):
n=int(input())
l=[];t=0;flg=0
for i in range(1,n+1,1):
    a,b=map(int,input().split())
    c=(b,a)
    l.append(c)
l.sort()
for x,y in l:
    t+=y
    if t>x:
        flg=1
if flg==0:print("Yes")
else:print("No")

Solution (Python):

N=int(input())
A=[0]*N
B=[0]*N
C=[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    C[i]=[A[i],B[i]]
C.sort(key=lambda x:(x[1],x[0]))
t=0
for i in range(N):
    t+=C[i][0]
    if C[i][1]<t:
        print('No')
        exit()
print('Yes')

Solution (Python):
def D_Megalomania():
    N = int(input())
    A = [0 for _ in range(N)]
    B = [[0,0] for _ in range(N)]
    for i in range(N):
        B[i][0] = i
        A[i], B[i][1] = map(int, input().split())

    B.sort(key=lambda x: x[1])
    output = "Yes"
    total_a = 0
    for i in range(N):
        total_a += A[B[i][0]]
        if total_a > B[i][1]:
            output = "No"
    print(output)

if __name__ == "__main__":
    D_Megalomania()

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

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

Solution (Python):
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


def IN_L_I():
  return list(map(int, input().split()))


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
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
'''


def MAIN():
  
  if A():
    print("Yes")
  else:
    print("No")


def A():
  n = IN_I()
  
  md = list([IN_L_I() for i in range(0, n)])
  md.sort(key=lambda x: (x[1]))
  total = 0
  for item in md:
    total += item[0]
    if total > item[1]:
      return False


  return True


def B():
  return None


def C():
  return None


MAIN()

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

def canFinishJobs(arr):
  arr.sort(key=lambda x: x[1])
  sum = 0
  for i in arr:
    sum += i[0]
    if sum > i[1]:
      return "No"
  return "Yes"

result = canFinishJobs(pairs)
print(result)

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

sorted_tasks = sorted(tasks, key=lambda x:x[1])
finish_time = 0
ans = "Yes"
for t in sorted_tasks:
    finish_time += t[0]
    if(finish_time > t[1]):
        ans = "No"
        break
print(ans)

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

lst = [list(map(int, input().split())) for s in range(N)]
lst = sorted(lst, key=lambda x: x[1], reverse=False)

s = 0
for a, b in lst:
    s += a

    if s > b:
        print('No')
        exit()

print('Yes')

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

lst = []

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

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

s = 0
for a, b in lst:
    s += a

    if s > b:
        print('No')
        exit()

print('Yes')

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]
def mi(n): return [wi() for _ in range(n)]
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
ab = mi(n)

ab.sort(key=ig(1))

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

Solution (Python):
import numpy as np

n = int(input())
a = np.array([list(map(int, input().split())) for _ in range(n)])
a_sorted = a[a[:, 1].argsort(), :]

a_sorted[:, 0] = np.cumsum(a_sorted[:, 0])
print("Yes" if all(map(lambda x: x[0] <= x[1], a_sorted)) else "No")

Solution (Python):


work_num = int(input())
work_list = []
for i in range(work_num):
    work_list.append(tuple(int(i) for i in input().split(" ")))


def ret_1th_element(tup):
    return tup[1]


work_list.sort(key=ret_1th_element)
time = 0
for i in work_list:
    time += i[0]
    if time > i[1]:
        print("No")
        break
else:
    print("Yes")

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

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

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


now = 0
for task in sorted_task:
    now += task[0]
    if now > task[1]:
        print("No")
        break
else:
    print("Yes")

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

jobs = []
for _ in range(n):
    jobs.append([int(i) for i in raw_input().split()])

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

finish_time = 0

result = True
for job in jobs:
    finish_time = finish_time + job[0]
    if finish_time > job[1]:
        result = False
        break

if result:
    print "Yes"
else:
    print "No"

Solution (Python):
from operator import itemgetter
a=int(input())
b=[list(map(int,input().split())) for i in range(a)]
b=sorted(b,key=itemgetter(1))
c=0
d=0
for i in range(a):
  c+=b[i][0]
  if c>b[i][1]:
    d=1
    break
    
if d==0:
  print("Yes")
else:
  print("No")

Solution (Python):
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")


def main():
    N = int(input())
    items = []

    for i in range(N):
        value, limit = map(int, input().split())
        items.append((limit, value))

    logging.info(items)

    items.sort()

    logging.info(items)

    total_time = 0
    for lim, val in items:
        total_time += val
        if total_time > lim:
            print("No")
            exit()

    print("Yes")

    
if __name__ == "__main__":
    main()

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

for i in range(n):
    vol, limit = map(int, input().split())
    task.append((limit, vol))   
    
task.sort()  

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

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

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

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

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

flag = 'Yes'
passed_time = 0
for d in data:
    A, B = d
    passed_time += A
    
    if passed_time > B:
        flag = 'No'
        
        break

print(flag)

Solution (Python):


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

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

sum = 0
for i in BList:
    sum += i[1]
    if (sum>i[0]):
        print("No")
        break

if(sum<=i[0]):
    print("Yes")

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

cur = 0
can = True
for b, a in e:
    cur += a
    if cur > b:
        can = False
        break

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

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

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

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

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

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



x = 0
flag = True
for i in range(N):
    a, b = data[i]
    x += a
    if x > b:
        flag = False

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

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted(a, key=lambda x: x[1])
judge = 0
flag = "Yes"
for j in range(n):
  judge += b[j][0]
  if(judge >  b[j][1]):
    print("No")
    flag = "No"
    break
    
if(flag == "Yes"):
  print("Yes")

Solution (Python):
from numpy import array, add

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

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

flg = True

a, b = array(jobs).T

s = add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted(a, key=lambda x: x[1])
judge = 0
flag = "Yes"
for j in range(n):
  judge += b[j][0]
  if(judge >  b[j][1]):
    print("No")
    flag = "No"
    break
    
if(flag == "Yes"):
  print("Yes")

Solution (Python):
import numpy as np

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

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

flg = True

a, b = np.array(jobs).T

s = np.add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Solution (Python):
import numpy as np

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

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

flg = True

a = np.array(jobs)[:,0]
b = np.array(jobs)[:,1]

s = np.add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

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

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

time = 0
flag = 0


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

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

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

time = 0
flag = 0


for k in range(n):
  time += works[k][0]
  if time > works[k][1]:
    flag = 1

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

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

works = sorted(works, key=lambda x: x[1])
work_time = 0
for w in works:
  work_time += w[0]
  if work_time > w[1]:
    print("No")
    break
else:
  print("Yes")

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

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

flg = True
sum = 0
for a, b in jobs:
    sum += a
    if sum > b:
        flg = False
        break

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

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

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

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

if flag == 0:
    print("Yes")

Solution (Python):
from operator import itemgetter

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

jobs.sort(key=itemgetter(1))

flg = True
sum = 0
for a, b in jobs:
    sum += a
    if sum > b:
        flg = False
        break

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

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

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

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

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

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

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

time = 0
ans = "Yes"
for a,b in info:
    time += a
    if time > b:
        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], -x[0]))

sum_a = 0
complete = True
for i in range(N):
    sum_a += AB[i][0]
    if sum_a > AB[i][1]:
        complete = False
if complete:
    print('Yes')
else:
    print('No')

Solution (Python):
import numpy as np
import sys

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

ls = ls[ls[:,1].argsort(), :]

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

Solution (Python):
import numpy as np
import sys

N = int(input())
ls = [list(map(int,input().split())) for i in range(N)]
ls = np.array(ls)
ls = ls[ls[:,0].argsort(), :]
ls = ls[ls[:,1].argsort(), :]

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

Solution (Python):
N=int(input())
A=[]
for i in range(N):
    a,b=list(map(int,input().split()))
    A.append([a,b])
A=sorted(A,key=lambda a:a[1])
m=0
s="Yes"
for a in A:
    m+=a[0]
    if m>a[1]:
      s="No"
      break
print(s)

Solution (Python):
N = int(input())
l_all = [list(map(int,input().split())) for i in range (N)]
l_all.sort(key = lambda x:x[1])
ryo = 0
for i in range(N):
    if l_all[i][1] < ryo + l_all[i][0]:
        print('No')
        exit()
    else:
        ryo += l_all[i][0]
print('Yes')

Solution (Python):


import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
s = sorted(a, key=itemgetter(1))
current_t = 0

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

Solution (Python):


import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
s = sorted(a, key=itemgetter(1))
current_t = 0

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

Solution (Python):
N = int(input())
ab = sorted([[int(x) for x in input().split()] for i in range(N)], key=lambda x:x[1])
fin = 1
if ab[0][0] > ab[0][1]:
    fin = 0
else:
    for i in range(1,N):
        ab[i][0] = ab[i-1][0] + ab[i][0]
        if ab[i][0] > ab[i][1]:
            fin = 0
            break

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

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


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


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

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

a=[0]*n
a[0]=x[0][0]
for i in range(1,n):
    a[i]=a[i-1]+x[i][0]

for j in range(n):
    if a[j] > x[j][1]:
        print("No")
        exit()

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")

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

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

tmp = 0
flg = 0

for j in range(n):
	tmp += sort_arr[j][0]
	if tmp > sort_arr[j][1]:
		flg = 1
		break

if flg ==1 :
	print('No')
else:
	print('Yes')

Solution (Python):
import operator

N = int(input())
W = []
for i in range(N):
	Ai,Bi = map(int,input().split())
	W.append((Ai,Bi))

W.sort(key = operator.itemgetter(1,0))

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = []

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

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

    time = 0

    for a, b in A:
        time += a
        if time > b:
            return 'No'

    return 'Yes'

print(main())

Solution (Python):

import math


n = int(input())

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

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

jobs = 0

for i in range(n):
    jobs += S[i][0]
    if jobs <= S[i][1]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
  n = int(input())
  task_list = [list(map(int,input().split())) for _ in range(n)]
  task_list.sort(key = lambda x:x[1])
  curr_time = 0 
  ans = 0 
  
  for k in task_list:
    curr_time += k[0]
    if curr_time > k[1]:
      ans = 1
      break

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

main()

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

Solution (Python):
N=int(input())
AB=[list(map(int,input().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")
        quit()
print("Yes")

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

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])

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

print('Yes')

Solution (Python):


N = int(input())

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


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

time = 0
result = True
for i in list:
    A, B = i
    time += A

    

    if time > B:
        result = False
        break

message = "Yes" if result else "No"
print(message)

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())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key = lambda A:A[1])
star_time = 0
ans = 'Yes'
for i in range(N):
    star_time += A[i][0]
    deadline = A[i][1]
    if deadline < star_time:
        ans = 'No'
print(ans)

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(N: int, A: "List[int]", B: "List[int]"):
    AB = [[a,b] for a,b in zip(A, B)]
    AB = sorted(AB, key = lambda x: x[1], reverse = True)

    tail = 100000000000
    for a, b in AB:
        tail = min(tail - a, b - a)
        if tail < 0:
            print('No')
            exit()
    else:
        print('Yes')
    
    return



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))
    solve(N, A, B)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
As, Bs = list(), list()
for i in range(N):
    A, B = map(int, input().split())
    As.append(A)
    Bs.append(B)

Bs_with_index = sorted([(Bs[i], i) for i in range(len(Bs))])
indices = list(map(lambda b: b[1], Bs_with_index))

time = 0
for index in indices:
    time += As[index]
    if time > Bs[index]:
        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])

time_sum = 0
flag = True
for i in range(n):
    time_sum = time_sum + ab[i][0]
    if time_sum > ab[i][1]:
        flag = False
        break

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