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



def f(AB):
    s = 0
    for a, b in sorted(AB, key=lambda x:x[1]):
        s += a

        if s > b:
            return 'No'

    return 'Yes'


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


if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    N = int(input())
    tasks = []
    for i in range(N):
        tasks.append(list(map(int, input().split())))
    tasks.sort(key=lambda x: x[1])
    t = 0
    for task in tasks:
        t += task[0]
        if t > task[1]:
            print('No')
            return
    print('Yes')
if __name__ == "__main__":
    main()

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

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

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

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

tasks=[]

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

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

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

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

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


now = 0
for k, v in items:
    if now + k <= v:
        now += k
        continue
    else:
        print("No")
        exit()
print("Yes")

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):
from sys import exit
INF = 10**21
N = int(input())
AB = [0 for i in range(N)]

for i in range(N):
    AB[i] = [int(n) for n in input().split()]
AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, key=lambda x: -x[1])

now = AB[0][1]
for i in range(len(AB)):
    now = min(AB[i][1], now)
    now -= AB[i][0]
if now < 0:
    print("No")
    exit()
else:
    print("Yes")

Solution (Python):
N = int(input())
W = []
for i in range(N):
    A,B = map(int,input().split())
    W.append([B,A])
W.sort()
time = 0
State = "Yes"
for i in range(N):
    time += W[i][1]
    if W[i][0] < time:
        State = "No"
        break
print(State)

Solution (Python):
n = int(input())
job = {}
for i in range(n):
    a, b = map(int, input().split())
    job[i] = (a, b)
job = sorted(job.items(), key=lambda k: k[1][1], reverse=True)
t = 1000000000
for k, v in job:
    c, d = v
    t = min(t, d) - c
if t < 0:
    print('No')
else:
    print('Yes')

Solution (Python):
N = int(input())
pairs = [[int(s) for s in input().split()] for _ in range(N)]
pairs.sort(key=lambda tup: tup[1])

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

Solution (Python):


import sys
from operator import itemgetter

n = int( sys.stdin.readline() )
tm = dict()
for _ in range(n):
    a,b = [ int(x) for x in sys.stdin.readline().split() ]
    tm[b] = tm.get(b,0) + a

s = 0
ans = 'Yes'
for b,a in sorted(tm.items(),key=itemgetter(0)):
    s += a
    if s>b:
        ans='No'
        break

print( ans )

Solution (Python):
import numpy as np
import sys

def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N = int(input())
    A = np.empty((N, 2))
    for i in range(N):
        A[i,:] = InputToInt()
    A = A[np.argsort(A[:, 0])]
    A = A[np.argsort(A[:, 1])]
    T = 0
    for i in range(N):
        T+=A[i, 0]
        if T > A[i, 1]:
            print('No')
            sys.exit()
    print('Yes')

Solution (Python):
N = int(input())
li = [ [int(it) for it in input().split()] for i in range(N) ]
li.sort( key=lambda x:x[1] )

s = 0
flag = True
for a,b in li:
    s += a
    flag = flag and s<=b
    
print ( "Yes" if flag else "No" )

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

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

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

Solution (Python):

n = int(input())
dt = [None] * n
for i in range(n):
    a, b = map(int, input().split())
    dt[i] = [b, a]
dt.sort()
t = 0
ans = True
for b, a in dt:
    if t + a > b:
        ans = False
    t += a
print(['No', 'Yes'][ans])

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

Solution (Python):
n=int(input())
time=[]
for i in range(n):
    a,b=map(int,input().split())
    time.append([a,b])
timesort=sorted(time,key=lambda x:(x[1]))
s=0
for i in range(n):
    s+=timesort[i][0]
    if s>timesort[i][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from operator import itemgetter
n=int(input())
li = [list(map(int, input().split())) for i in range(n)]
li.sort(key=itemgetter(1)) 

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

print("Yes")

Solution (Python):


from operator import itemgetter

def solve(n,arr):
	sarr1 = sorted(arr, key=itemgetter(1))
	cur = 0
	
	for i in range(n):
		t = sarr1[i]
		cur = cur + t[0]
		
		if cur > t[1]:
			return 'No'
	return 'Yes'

n = int(input())
arr = []
for i in range(n):
	_a,_b = map(int, input().split())
	arr.append((_a, _b))

ans = solve(n,arr)
print(ans)

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

ans="Yes"
a_sum=0
for i in range(N):
	a=B[i][0]
	b=B[i][1]
	
	a_sum+=a
	if a_sum>b:
		ans="No"
		break


print(ans)

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

C.sort(key=lambda c: c[0])
C.sort(key=lambda c: c[1])

x = 0
p = True
for c in C:
    x += c[0]
    if x > c[1]:
        p = False
        break
print('Yes' if p else 'No')

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

l.sort()
tmp = 0
for i in range(N):
    tmp += l[i][1]
    if tmp > l[i][0]:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys
sys.setrecursionlimit(10**7)


debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

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

    from operator import itemgetter
    ltask.sort(key=itemgetter(1))

    ans = "Yes"
    time = 0
    for task in ltask:
        time += task[0]
        if time > task[1]:
            ans = "No"
            break

    print(ans)

solve()

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

from operator import itemgetter

AB.sort(key = itemgetter(1))

cost = 0

ans = 'Yes'
for a,b in AB:
    cost += a
    if cost > b:
        ans = 'No'
        break
print(ans)

Solution (Python):
import sys

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

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

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

Solution (Python):
from sys import stdin
import numpy as np
from operator import itemgetter

N = int(stdin.readline().rstrip().split()[0])
AB = []
for i in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    AB.append((a,b))

AB = sorted(AB, key=itemgetter(1))
Frag = "Yes"
time=0
for a,b in AB:
    time += a
    if time>b:
        Frag="No"
        break

print(Frag)

Solution (Python):
n = int(input())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append([b,a])
L.sort()
cur = 0
flag = True
for i in range(n):
    cur += L[i][1]
    if cur > L[i][0]:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    C = [LIST() for i in range(N)]
    C.sort(key=lambda x:x[1])
    sum = 0
    for i in range(N):
        sum += C[i][0]
        if sum > C[i][1]:
            No()
            exit()
    Yes()

if __name__ == '__main__':
    main()

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def solve():
  N = readInts()[0]
  tasks = [tuple(readInts()) for _ in range(N)]
  tasks.sort(key=lambda x: x[1], reverse=True)

  t = tasks[0][1] - tasks[0][0]
  if t < 0:
    return False

  for i in range(1, N):
    if t > tasks[i][1]:
      t = tasks[i][1]
    t -= tasks[i][0]
    if t < 0:
      return False

  return True

def main():
  ans = solve()
  if ans:
    print("Yes")
  else:
    print("No")

if __name__ == "__main__":
  main()

Solution (Python):
def main():
	import sys
	from operator import itemgetter
	input = sys.stdin.readline
	N = int(input())
	AB = [list(map(int, input().split())) for _ in range(N)]
	AB.sort(key=itemgetter(1,0))
	sum = 0
	for i in range(N):
		sum += AB[i][0]
		if sum > AB[i][1]:
			print('No')
			sys.exit()
	print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):



import sys
sys.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
sys.setrecursionlimit(10000000)






import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce, lru_cache


from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))




def main():
    N, = list(map(int, input().split()))
    T = [None for i in range(N)]
    for i in range(N):
        T[i] = tuple(list(map(int, input().split())))
    T.sort(key = lambda t: t[1] * 1e10 + t[0])

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


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())

tasks = list()
for _ in range(n):
    a, b = map(int, input().split())
    tasks.append((a, b))

sorted_tasks = sorted(tasks, key=lambda x: -x[1], reverse=True)

flag = True
time = 0
for a, b in sorted_tasks:
    time += a
    if time > b:
        flag = False
        break

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

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

cnt = 0
BA = [[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1] = AB[i][0]
    BA[i][0] = AB[i][1]
BA.sort()
for i in range(N):
    cnt += BA[i][1]
    BA[i][1] = cnt
ans = "Yes"
for i in range(N):
    if BA[i][0] < BA[i][1]:
        ans = "No"
        break

print(ans)

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

n = int(input())
time = []
flag = True
now = 0

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

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

for i in range(n):
    now += time[i][0]
    if now <= time[i][1]:
        pass
    else:
        flag = False

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

Solution (Python):

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

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


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


t=0
k=0
for i in range(N):

    t+=a[i][0]
    if t<= a[i][1]:
        k=k
    else:
        k+=1
if k==0:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
import sys
from collections import deque  
from collections import defaultdict  
from heapq import heapify, heappush, heappop, heappushpop  
from bisect import bisect_left, bisect_right  



s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N = i2n()
    AB = ii2nnn(N)
    AB.sort(key=lambda v: v[1])
    t = 0
    for a, b in AB:
        t += a
        if t > b:
            print('No')
            return
    print('Yes')

main()

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

time=0
for task in tasks:
    time+=task[0]
    if task[1]-time>=0:
        pass
    else:
        print('No')
        exit(0)
print('Yes')

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

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

Solution (Python):


def read_input():
    n = int(input())

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

    return n, conds


def submit():
    n, conds = read_input()

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

    curr = 0
    for c in conds:
        curr += c[0]

        if curr > c[1]:
            print('No')
            return

    print('Yes')
    return


if __name__ == '__main__':
    submit()

Solution (Python):
def abc():
    n = int(input())
    tasks = []
    for i in range(n):
        a, b = map(int, input().split())
        tasks.append((a, b))
    tasks.sort(key=lambda x: x[1])
    tmp = 0
    for t in tasks:
        a, b = t
        if tmp + a > b:
            print('No')
            return
        tmp += a
    print('Yes')


abc()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

n = II()
tasks = [0 for i in range(n)]
for i in range(n):
    tasks[i] = LI()
tasks = sorted(tasks, key=lambda x: x[1])
load = 0
for i in range(n):
    load += tasks[i][0]
    if load > tasks[i][1]:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

c = 0
for i in range(N):
    x, y = L[i]
    
    c += x
    if c > y:
        print("No")
        exit()
      
print("Yes")

Solution (Python):
N = int(input())
para = [[i for i in map(int,input().split())] for j in range(N)]
para.sort(key=lambda x:x[1])
time = 0 
for i in range(N):
    time += para[i][0]
    if time > para[i][1]:
        print("No")
        exit()

print("Yes")

Solution (Python):
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

N = ni()
L = [na() for i in range(N)]

L.sort(key=lambda x:x[1])
t = 0
for a,b in L:
    t+=a
    if b<t:
        print("No")
        exit()

print("Yes")

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

t= 0
ans = "Yes"
for ab in ls:
  t += ab[0]
  if t > ab[1]:
    ans = "No"
    break
    
print(ans)

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

def solve():
    time = 0
    for task in ab:
        if task[1] < task[0]+time:
            return False
        time = task[0]+time
    return True

res = solve()
if res:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
from operator import itemgetter
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
c=sorted(ab, key=itemgetter(1), reverse=False)
f=True
t=0
for i in range(n):
    t = t + c[i][0]
    f=f and t<=c[i][1]
if f:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
ab_list = [[int(x) for x in input().split()] for _ in range(N)]
sorted_ab_list = sorted(ab_list, key=lambda ab: ab[1])
t = 0
for a, b in sorted_ab_list:
    t += a
    if (t <= b):
        continue
    else:
        print("No")
        exit()
print("Yes")

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

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

time = 0
ans = True

for i in range(N) :
    time += AB[i][0]
    if time > AB[i][1] :
        ans = False
        break

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

Solution (Python):
from sys import stdin, exit

N = int(stdin.readline().rstrip())
work = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

work.sort(key=lambda x: x[1])
time = 0
for k in range(N):
    if time + work[k][0] > work[k][1]:
        print('No')
        exit()
    time += work[k][0]
print('Yes')

Solution (Python):
import sys
from operator import itemgetter

input = sys.stdin.readline

N = int(input())

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

task_list.sort(key=itemgetter(1))

deadline = 0
time = 0

for task in task_list:
    time += task[0]
    deadline = task[1]
    if deadline < time:
        print("No")
        exit()

print("Yes")

Solution (Python):
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
a=sorted(a, key=lambda x:x[1])
ans='Yes'
now=0
for i,j in a:
    now+=i
    if j<now:
        ans='No'
print(ans)

Solution (Python):










import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = [0] * n
    ans = 'Yes'
    d = {}
    for i in range(n):
        arr[i] = get_array()
        if arr[i][0] > arr[i][1]:
            ans = 'No'
        if arr[i][1] not in d:
            d[arr[i][1]] = 0
        d[arr[i][1]] += arr[i][0]
    if ans == 'No':
        print(ans)
        return
    od = sorted(list(d.items()))
    d = []
    for i in od:
        d.append([i[0], i[1]])
    for i in range(1, len(d)):
        d[i][1] += d[i - 1][1]

    for i in d:
        if i[0] < i[1]:
            ans = 'No'
            break

    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


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


if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(1,N+1):
  inf = input().split()
  a = int(inf[0])
  b = int(inf[1])
  dic[b] += [a]

keys = list(dic.keys())
keys.sort()
ps = 0

for k in keys:
  ls = dic[k]
  need = sum(ls)
  ps += need
  if ps>k:
    print('No')
    break
else:
  print('Yes')

Solution (Python):
import heapq
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
flg = True
for i in range(N):
    b,a = heapq.heappop(q)
    time += a
    
    if b < time:
        flg = False
if flg:
    print("Yes")
else:
    print("No")

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

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

idx = sorted(range(len(B)), key=lambda k: B[k])
time = 0
answer = 'Yes'
for i in idx:
    time += A[i]
    if (time > B[i]):
        answer = 'No'
        break

print(answer)

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

current_time = 0
answer = 'Yes'
for t in sorted(task, key=lambda x: x[1]):
    current_time += t[0]
    if current_time > t[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])

time=0
for ab in AB:
    time+=ab[0]
    if time > ab[1]:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
N=int(input().strip())
a=[]
for i in range(N):
    array=list(map(int,input().strip().split()))
    a.append(array)
b=sorted(a, key=lambda x:x[1])
n,t,f=0,0,0
while True:
    t+=b[n][0]
    if t>b[n][1]:
        f=1
        break
    n+=1
    if n==N:
        break
if f==1:
    print('No')
else:
    print('Yes')

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

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

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

def check(ab_list):
    goukei = 0
    for a,b in ab_list:
        goukei += a
        if b < goukei:

            return False
    return True

if check(ab_list):
    print("Yes")
else:
    print("No")

Solution (Python):
words = lambda t : list(map(t, input().split()))

n = int(input())
xs = []
for i in range(n):
    a,b = words(int)
    xs.append((b,a))

xs.sort()

ttl = 0
succeed = True
for b,a in xs:
    ttl += a
    if ttl > b:
        succeed = False
        break

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

Solution (Python):
def d_megalomania(N, Tasks):
    tasks = sorted(Tasks, key=lambda x: x[1])
    time = 0
    for a, b in tasks:
        time += a
        if time > b:
            return 'No'
    return 'Yes'

N = int(input())
Tasks = [[int(i) for i in input().split()] for j in range(N)]
print(d_megalomania(N, Tasks))

Solution (Python):
import numpy as np

n = int(input())
lst = [[0]*2 for i in range(n)]

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

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

a = np.array(lst).T.tolist()[0]
b = np.array(lst).T.tolist()[1]

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

print(ans)

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

end = 0
ans = 0
AB = sorted(AB,key=lambda x:x[1])
t = 0
for y in AB:
    t += y[0]
    if t > y[1]:
        print("No")
        exit()



print("Yes")

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

N = int(input())
A = [0] * N
B = [0] * N
l = []

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

l.sort()
sum = 0
flag = 0

for i in range(N):
	sum += l[i][1]
	if sum > l[i][0]:
		flag = 1
		
if flag == 1:
	print('No')
else:
	print('Yes')

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

L.sort()


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

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n=int(input())
l=[list(intinput()) for i in range(n)]
l.sort(key=lambda x:x[1])
k=0
for i,j in l:
    k+=i
    if k>j:
        print("No")
        break
else:
    print("Yes")

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

Solution (Python):

import sys
import math
import numpy as np
import itertools



n = int(input())

ab = [[int(i) for i in input().split()] for i in range(n)] 





ab = sorted(ab, key=lambda x:x[1])
t=0
for i in range(n):
    t += ab[i][0]
    if ab[i][1]<t:
        print('No')
        exit()

print('Yes')

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

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

Solution (Python):
import heapq


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

    heapq.heapify(q)

    t = 0
    while q:
        b, a = heapq.heappop(q)
        t += a
        
        if t > b:
            print("No")
            return
    print("Yes")



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [0] * n
b = [0] * n
infob= [[0,0] for _ in range(n)]

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

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

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

print(ans)

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

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


total_amount = sum([w[0] for w in works])


can_fin = True
for amount, deadline in reversed(works):
    if total_amount > deadline:
        can_fin = False
        break
    total_amount -= amount
    
if can_fin:
    print('Yes')
else:
    print('No')