Problem:
 Score: 400 points    Problem Statement  Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0 . Kizahashi has N jobs numbered 1 to N .  It takes A_i units of time for Kizahashi to complete Job i . The deadline for Job i is time B_i , and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print Yes ; if he cannot, print No .      Constraints   All values in input are integers.  1 \leq N \leq 2 \times 10^5  1 \leq A_i, B_i \leq 10^9 (1 \leq i \leq N)         Input  Input is given from Standard Input in the following format:  N  A_1  B_1  .  .  .  A_N  B_N       Output  If Kizahashi can complete all the jobs in time, print Yes ; if he cannot, print No .        Sample Input 1 5
2 4
1 9
1 8
4 9
3 12      Sample Output 1 Yes  He can complete all the jobs in time by, for example, doing them in the following order:   Do Job 2 from time 0 to 1 .  Do Job 1 from time 1 to 3 .  Do Job 4 from time 3 to 7 .  Do Job 3 from time 7 to 8 .  Do Job 5 from time 8 to 11 .   Note that it is fine to complete Job 3 exactly at the deadline, time 8 .       Sample Input 2 3
334 1000
334 1000
334 1000      Sample Output 2 No  He cannot complete all the jobs in time, no matter what order he does them in.       Sample Input 3 30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720      Sample Output 3 Yes

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

total = 0
for a, b in ab:
    total += a
    if total <= b:
        continue
    else:
        print("No")
        exit()
else:
    print("Yes")

Solution (Python):
n = int(input())
apple = []
for _ in range(n):
    a, b = map(int, input().split())
    apple.append([b, a])
apple = sorted(apple)
count = 0
s = 0
for i in apple:
    if count + i[1] <= i[0]:
        s += 1
        count += i[1]
    else:
        s = 0
        break
print("Yes" if s==n else "No")

Solution (Python):
n=int(input())
t=[]
for i in range(n):
  at,bt=map(int,input().split())
  t.append([bt,at])
t.sort()
temp=0
for i in range(n):
  temp=temp+t[i][1]
  if temp>t[i][0]:
    print("No")
    break
else:
  print("Yes")

Solution (Python):
n = int(input())
a_li = [[0]*2 for i in range(n)]
for i in range(n):
    a_li[i][1],a_li[i][0] = map(int,input().split())
a_li.sort()
time = 0
for i in range(n):
    time += a_li[i][1]
    if time > a_li[i][0]:
        print("No")
        exit()
print("Yes")

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

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

Solution (Python):
from collections import defaultdict
n=int(input())

d=defaultdict(int)
for i in range(n):
    a,b =map(int,input().split())
    d[b]+=a

d_sorted=sorted(d.items(), key=lambda x: x[0])

time=0
finished=True
for i in range(len(d_sorted)):
    time+=d_sorted[i][1]
    if time>d_sorted[i][0]:
        finished=False
        break

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

Solution (Python):
n = int(input())
ba = []
now = 0
ans = "Yes"

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

for i in range(n):
    now += ba[i][1]
    
    if ba[i][0] < now:
        ans = "No"
        break
        
print(ans)

Solution (Python):
import sys
n = int(input())
t = 0
ls = [list(map(int,input().split())) for _ in range(n)]
ls = sorted(ls,key=lambda x:x[1])
for i in range(n):
    if ls[i][1]-t < ls[i][0]:
        print("No")
        sys.exit()
    else:
        t += ls[i][0]
print("Yes")

Solution (Python):
import sys

read = sys.stdin.buffer.read


def main():
    N, *AB = map(int, read().split())
    T = [0] * N
    for i, (a, b) in enumerate(zip(AB[::2], AB[1::2])):
        T[i] = [b, a]

    T.sort()

    ok = True
    sum_a = 0
    for b, a in T:
        sum_a += a
        if sum_a > b:
            ok = False
            break

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

    return


if __name__ == '__main__':
    main()

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

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

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

gokei = 0
for i in A:
    gokei += i[0]
    if gokei > i[1]:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

t = 0
ans = 'Yes'

for i in range(n):
	l = tsk[i]
	t += l[0]
	if t > l[1]:
		ans = 'No'
		break
print(ans)

Solution (Python):
def main():
    N = int(input())
    task = [list(map(int, input().split())) for i in range(N)]
    task.sort(key = lambda x : x[1])
    time = 0

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

    print("Yes")

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    
    n = int(input())
    a_b = [list(map(int, input().split())) for i in range(n)]
    a_b = sorted(a_b, key=lambda x: x[1])

    time_space = 0
    for i in range(len(a_b)):
        if i == 0:
            time_space = a_b[i][1] - a_b[i][0]
        else:
            time_space = a_b[i][1] - a_b[i - 1][1] - a_b[i][0] + time_space

        if time_space < 0:
            print("No")
            return

    print("Yes")



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """5
2 4
1 9
1 8
4 9
3 12"""
        output = """Yes"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
334 1000
334 1000
334 1000"""
        output = """No"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """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"""
        output = """Yes"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

Solution (Python):
n=int(input())
num=[]
def ap(num1):
    num.append(num1)
for i in range(n):
    ap(list(map(int,input().split())))
num2=0
str1= lambda val: val[1]
num.sort(key=str1)
ans=0
for i in range(n):
    num2+=num[i][0]
    if num2>num[i][1]:
        ans=1
        break
if ans==1:
    print("No")
else:
    print("Yes")

Solution (Python):
n=int(input())
num=[]
def ap(num1):
    num.append(num1)
for i in range(n):
    ap(list(map(int,input().split())))
num2=0
str1= lambda val: val[1]
num.sort(key=str1)
ans=0
for i in range(n):
    num2+=num[i][0]
    if num2>num[i][1]:
        ans=1
        break
if ans==1:
    print("No")
else:
    print("Yes")

Solution (Python):
N = int(input())
job = [list(map(int, input().split())) for _ in range(N)]
job.sort(key=lambda x: x[1])
time = 0
FLG = True

for need, limit in job:
    time += need
    if time > limit:
        FLG = False
        break

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

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

n = int(input())

readline = sys.stdin.readline

d = {}

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    d[b] = d.get(b, 0) + a

d_sorted = sorted(d.items(), key=lambda x:x[0])

s = 0
for t, w in d_sorted:
    s += w
    if s > t:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append([b, a])
ab.sort()
time = 0
for b, a in ab:
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from operator import itemgetter

n = int(input())
l = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(1))

count = 0
Work = True
for i in range(n):
    if count + l[i][0] > l[i][1]:
        Work = False
        break
    else:
        count += l[i][0]

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

Solution (Python):
n = int(input())
ab = [tuple(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')
        exit()
print('Yes')

Solution (Python):

import collections
















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
AB = [readInts() for _ in range(n)]

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

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

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())
ab = [list(map(int, input().split())) for _ in range(n)]

ab.sort(key=lambda i: i[1])
t = 0
for i in ab:
  t += i[0]
  if t > i[1]:
    print("No")
    exit()
print("Yes")

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

import sys

a.sort(key=lambda x: x[1])
sum=a[0][0]
for i in range(n-1):
  if sum>a[i][1]:
    print("No")
    sys.exit()
  sum=sum+a[i+1][0]
if sum>a[n-1][1]:
  print("No")
  sys.exit()
print("Yes")

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

Solution (Python):
n=int(input())
ab=[[0]*2 for ii in range(n)]
for ii in range(n):
	ab[ii][1],ab[ii][0]=map(int,input().split())


ab.sort(reverse=True)

r=ab[0][0]
for ii in range(n):
  r=min(ab[ii][0],r)-ab[ii][1]
  if r<0:
    print("No")
    exit()

print("Yes")

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

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

time = 0
for a, b in data:
    time += a
    if (time > b):
        print('No')
        exit()
    else:
        pass

print('Yes')

Solution (Python):


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

def check(l):
    t = 0 
    for end, worktime in l:
        t += worktime
        if t > end:
            return 'No'
            break
            
    return 'Yes'
print(check(l))

Solution (Python):
def main():
    n = int(input())
    ABs = [list(map(int, input().split())) for _ in range(n)]
    ABs = sorted(ABs, key=lambda x: x[1])
    Count = 0
    for AB in ABs:
        Count += AB[0]
        if Count > AB[1]:
            print("No")
            exit()
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
import bisect

N = int(input())

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

Sum = 0

for i in range(N):
    Sum = Sum + L[i][1]
    if Sum <= L[i][0]:
        continue
    else:
        print("No")
        quit()
print("Yes")

Solution (Python):
class Work:
    require = 0
    limit = 0
    def __init__(self, require, limit) -> None:
        self.require = require
        self.limit = limit

def from_list(xs) -> Work: 
    return Work(xs[0], xs[1])

N = int(input())

works = [from_list([int(_) for _ in input().split()]) for i in range(N)]

def solve(works):
    works.sort(key=lambda x: x.limit)
    acc = 0
    for w in works:
        acc += w.require
        if acc > w.limit:
            return "No"
    return "Yes"

print(solve(works))

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

Works = [dict(zip(["require", "limit"], [int(_) for _ in input().split()])) for i in range(N)]

def solve(Works):
    Works.sort(key=lambda x: x["limit"])
    acc = 0
    for w in Works:
        acc += w["require"]
        if acc > w["limit"]:
            return "No"
    return "Yes"

print(solve(Works))

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

for a,b in W:
    t+=a
    if t>b:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
num = int(input())
work = []
for i in range(num):
    work.append(list(map(int,input().split(' '))))
work.sort(key = lambda a: a[1])
time = 0
limit  = 0
cant_flg = 0
for w in work:
    limit = w[1]
    time += w[0]
    if(limit<time):
        print('No')
        cant_flg = 1
        break
if(cant_flg==0):
    print('Yes')

Solution (Python):
import sys
import math
from collections import deque
import heapq

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    A = []
    for i in range(N):
        a, b = NMI()
        A.append([a, b])
    A.sort(key=lambda x: x[1])
    t = 0
    for a in A:
        t += a[0]
        if t > a[1]:
            print("No")
            exit()

    print("Yes")



if __name__ == "__main__":
    main()

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

works = []
for work in range(N):
    a, b = [int(i) for i in input().split()]
    works.append((a, b))
    
works.sort(key=lambda x: x[1])

time_cnt = 0
flag = True
for work in works:
    t = work[0]
    l = work[1]
    time_cnt += t
    if time_cnt > l:
        flag = False
        break
        
if flag:
    print('Yes')
else :
    print('No')

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

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

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

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

cur = 0
for a,b in W:
  if cur+a > b:
    print("No")
    exit()
  cur += a 

print("Yes")

Solution (Python):
N=int(input())
a=[0]*N
b=[0]*N
genzai=0
AB=[]
for i in range(N):
    A,B=map(int,input().split())
    a[i]=A
    b[i]=B
    AB.append([B,A])
AB.sort()
for i in range(N):
    genzai+=AB[i][1]
    if genzai>AB[i][0]:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
AB = [LI() for _ in range(N)]
AB = sorted(AB, key=lambda x:x[1])
time = 0
for a,b in AB:
    time += a
    if time>b:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
import math

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

jt = 0
for a, b in ab:
    jt += a
    if b < jt:
        print("No")
        exit()

print("Yes")

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

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

time = 0

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

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

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

time = 0

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

Solution (Python):
N = int(input())
works = []
time = 0
for _ in range(N):
    cost, deadline = map(int, input().split())
    works.append((deadline, cost))

works.sort()


for item in works:
    deadline, cost = item[0], item[1]
    
    
    time += cost
    if time > deadline:
        print('No')
        exit()

print('Yes')

Solution (Python):
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
L = sorted(l, key = lambda x:x[1])
cumsum = 0
for i in range(n):
    cumsum += L[i][0]
    if cumsum > L[i][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
    N = int(input())
    jobs = [list(map(int, input().split())) for _ in range(N)]
    time = 0
    jobs = sorted(jobs, key=lambda x: x[1])
    for j in jobs:
        time += j[0]
        if time > j[1]:
            print("No")
            return
        
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    jobs = []
    time = 0
    for _ in range(N):
        A, B = map(int, input().split())
        jobs.append((A, B))

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = []
    for _ 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'

if __name__ == '__main__':
    print(main())

Solution (Python):
import numpy as np

N = int(input())
AB = np.array([[int(x) for x in input().split()] for _ in range(N)])
A = AB[:,0]
B = AB[:,1]
idx = B.argsort()
A = A[idx]
B = B[idx]
np.cumsum(A, out = A)
bl = (A <= B).all()
answer = 'Yes' if bl else 'No'
print(answer)

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()


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

    AB.sort(key=lambda x: x[1])
    asum = [0 for _ in range(N + 1)]
    for i in range(N):
        asum[i + 1] = asum[i] + AB[i][0]

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

    print(ans)


if __name__ == '__main__':
    solve()

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

for i in range(N):
    Q.append(tuple(map(int, input().split())))

Q = sorted(Q, key=lambda x: x[1])
now = 0
for i in range(N):
    if now + Q[i][0] <= Q[i][1]:
        now += Q[i][0]
    else:
        print("No")
        exit()

print("Yes")

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
A, B = [list(i) for i in zip(*AB)]
t = 0
bl = True
for i in range(N):
    t += A[i]
    if t > B[i]:
        bl = False

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

Solution (Python):
from sys import exit

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

job.sort(key=lambda x: x[1])
time = 0
for a, b in job:
    time += a
    if time > b:
        print('No')
        exit()
print('Yes')

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


S = [[0 for j in range(2)] for i in range(N)]

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


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

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

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


n = I()
ab = [LI() for _ in range(n)]
ab_s = sorted(ab, key=lambda x: x[1])
coll_t = 0
ans = 'Yes'
for a, b in ab_s:
    coll_t += a
    if coll_t > b:
        ans = 'No'
        break

print(ans)

Solution (Python):
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)
def f(heap):
	t = 0
	while(heap):
		nd,d = heapq.heappop(heap)
		gap = nd - t - d
		if gap < 0:
			return False
		t += d
		
	return True
print 'Yes' if f(heap) else 'No'

Solution (Python):
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)

def f(heap):
	t = 0
	while(heap):
		nd,d = heapq.heappop(heap)
		gap = nd - t 
		gap -= d
		t += d
		while(heap and heap[0][0] == nd):
			_,v = heapq.heappop(heap) 
			t += v
			gap -= v
		if gap < 0: return False
	return True
print 'Yes' if f(heap) else 'No'

Solution (Python):
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)

def f(heap):
	t = 0
	while(heap):
		nd,ct = heapq.heappop(heap)
		while(heap and heap[0][0] == nd): ct += heapq.heappop(heap)[1]
		gap = nd - ct - t
		if gap < 0:
			return False
		while(heap and heap[0][1] <= gap):
			u,v = heapq.heappop(heap)
			gap -= v
			t += v
		t += ct
	return True
print 'Yes' if f(heap) else '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()
print('Yes')

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        n=int(input())
        l=[list(map(int,input().split())) for i in range(n)]
        l.sort(key=lambda x:x[1])
        time=0
        for x,y in l:
            time+=x
            if time>y:
                return 'No'
        return 'Yes'
    print(main())

resolve()

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

for i in ab:
    t += i[0]
    if i[1] < t:
        break
else:
    ans = 'Yes'

print(ans)

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
ts = []
for i in range(n):
    a, b = map(int, readline().split())
    ts.append((b, a))
ts = sorted(ts, key=lambda x:(x[0], -x[1]))

now = 0
for t in ts:
    now += t[1]
    if now > t[0]:
        print("No")
        exit()
print("Yes")

Solution (Python):
n = int(input())
ab = []
A = 0

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

ab.sort()

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

Solution (Python):

from operator import itemgetter
n = int(input())
t = [list(map(int,input().split())) for i in range(n)]

t.sort(key=lambda x: x[1])
cost = 0
for i in t:
    cost += i[0]
    if cost > i[1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
N = int(input())
BA = []
for _ in range(N):
    a, b = map(int, input().split())
    BA.append((b, a))
BA.sort()
time = 0
is_timeover = False
for i in range(N):
    b, a = BA[i]
    time += a
    if time > b:
        is_timeover = True
        break

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

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

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

Solution (Python):
N = int(input())
ls = [[int(i) for i in input().split()] for j in range(N)]
now = 0
ls = sorted(ls,key=lambda x:x[1])
ans = 'Yes'
for l in ls:
    now += l[0]
    if now > l[1]:
        ans = 'No'
        break
print(ans)

Solution (Python):
n = int(input())
AB = []
import collections
d_ba = collections.defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    d_ba[b] += a

time = 0
for b in sorted(d_ba):
    if time + d_ba[b] <= b:
        time += d_ba[b]
    else:
        print('No')
        exit()
print('Yes')

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

work = sorted([list(map(int,input().split())) for i in range(N)], key = lambda x: x[1])
dead = [w[1] - w[0] for w in work]

now = 0

for i in range(N):
  if now > dead[i]:
    ans = "No"
    break
  now += work[i][0]
else:
  ans = "Yes"

print(ans)

Solution (Python):
import numpy as np

N = int(input())
lst=[]
for i in range(N):
    lst.append(list(map(int,input().split())))
AB=np.array(lst).reshape(N,2).T
A = AB[0]
B = AB[1]
ind = B.argsort()
A = A[ind]
B = B[ind]
if np.all(A.cumsum() <= B):
    print("Yes")
else:
    print("No")

Solution (Python):
n=int(input())
l=[]
for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
l=sorted(l,key=lambda x:x[1],reverse=True)

cnt=l[0][1]
for i in range(n):
    if cnt>l[i][1]:
        cnt=l[i][1]
    cnt-=l[i][0]
if cnt>=0:
    print("Yes")
else:
    print("No")

Solution (Python):
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: (x[1], -x[0]))
    d = 0
    for a, b in ab:
        d += a
        if d > b:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
N = int(input())
job = [[0]*2 for i in range(N)]
time = 0
for i in range(N):
    l = list(map(int, input().split()))
    job[i][0], job[i][1] = l[1], l[0]
job = sorted(job)
for i in range(N):
    time += job[i][1]
    if time > job[i][0]:
        print("No")
        break
    elif i == N-1:
        print("Yes")

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

Solution (Python):
N = int(input())
lis = []
for i in range(N):
    lis.append(list(map(int,input().split())))
lis = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()

N = ini()
tasks = []
for i in range(N):
    a, b = inm()
    tasks.append((b, a))
tasks.sort()


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


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

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])
t = 0
for task in tasks:
    t += task[0]
    if t > task[1]:
        print("No")
        exit()
print("Yes")

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

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

Solution (Python):
import sys


if __name__ == "__main__":
    n = int(input())
    ab = []
    for i in range(n):
        a,b = map(int,input().split())
        ab.append([a,b])
    ab.sort(key= lambda x:x[1])
    time = 0
    for i in range(n):
        if time + ab[i][0] <= ab[i][1]:
            time += ab[i][0]
        else:
            print("No")
            sys.exit()
    print("Yes")

Solution (Python):

import sys
input = sys.stdin.readline
N = int(input())
A =[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append((a,b))

now =0
A_sort =sorted(A,key=lambda x: x[1])
for  progress,deadline in A_sort:
    now +=progress
    if now <=deadline:
        ans ="Yes"
    else:
        ans ="No"
        break
print(ans)

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

N = int(input())
task_list = []
heapify(task_list)
for i in range(0,N,1):
    a,b = map(int,input().split())
    heappush(task_list,[b,a])

now_time = 0
while len(task_list)>0:
    b,a = heappop(task_list)
    now_time += a
    if now_time > b:
        print("No")
        exit()
print("Yes")

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

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

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

Solution (Python):
N, *AB = map(int, open(0).read().split())
AB = [(B, -A) for A, B in zip(AB[::2], AB[1::2])]
AB.sort()
t = 0
for b, a in AB:
    a = -a
    t += a
    if t > b:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
from collections import deque
N = int(input())

tasks = []

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

tasks.sort(key=lambda x: x[1])
dq = deque(tasks)

time = 0
task_over = False
for i in range(N):
    tmp = dq.popleft()
    time += tmp[0]
    if time > tmp[1]:
        task_over = True
        break

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

Solution (Python):
N=int(input())
works=[]
for _ in range(N):
    A,B=map(int,input().split())
    works.append([B,A])
n_works=sorted(works)
answer=0
number=0
for work in n_works:
    number+=work[1]
    if number>work[0]:
        answer=1
        break
if answer==0:
    print('Yes')
else:
    print('No')

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

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

print("Yes")

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