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

import sys
input = sys.stdin.readline


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

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

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

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

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

Solution (Python):
import sys
a=int(input())
b=sorted([list(map(int,input().split())) for i in range(a)],key=lambda x:x[1])
sofar=0
flag=True
for i in b:
    sofar+=i[0]
    if sofar>i[1]:
        print('No')
        sys.exit()
print('Yes')

Solution (Python):
a=int(input())
b=sorted([list(map(int,input().split())) for i in range(a)],key=lambda x:x[1])
sofar=0
flag=True
for i in b:
    sofar+=i[0]
    if sofar>i[1]:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
import sys

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

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



time = 0

for i in range(N):
    task = TASKS[i]
    a = task[0]
    b = task[1]
    time += a
    if time <= b:
        continue
    else:
        print("No")
        sys.exit()

print("Yes")

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

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

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

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


main()

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

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

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

flg = True
a = 0
for i in job:
  a += i[0]
  if(a > i[1]):
    flg = False
    break

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

Solution (Python):
from operator import itemgetter

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

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

work = sorted(work, key=itemgetter(1))

t = 0
ans = True

for i in range(N):
    t += work[i][0]
    if(t > work[i][1]):
        ans = False
        break
if ans == True:
    print('Yes')
else:
    print('No')

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

nums = [list(map(int, input().split())) for _ in range(n)]
current_time = 0
ans = "Yes"

"""
n = [[作業にかかる時間, 作業が終了していないといけない時間]]の2次元配列で複数渡ってくる
すべての作業を、作業が完了していないといけない時間までに終えることができるか？

n = [
[3, 12], [2, 6], [1, 2]
]

作業の締切が優先されるので締め切り順に整頓する
[1,2],[2,6],[3,12]

作業には作業時間掛かるので、現在時刻に作業時間を加算する。すべての加算された時間が最後まで締め切り時間以内(締切時間に終了しても大丈夫)であればok
1個め=現在時刻1, 2個め=現在時刻3 3個め=現在時刻6 締切は2, 6, 12なのでok
"""

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


for i in nums:
    current_time = current_time + i[0]
    if current_time > i[1]:
        ans = "No"

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])
ans = 0
T = 0

for i in range(N):
    if(T+ab[i][0] <= ab[i][1]):
        ans+=1
        T += ab[i][0]
        
print(["Yes", "No"][ans!=N])

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

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

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

T = 0
R = "Yes"
for a, b in AB:
    T += a
    if T > b:
        R = "No"

print(R)

Solution (Python):
import sys

N=input()
AB=[ tuple( map(int, sys.stdin.readline().split()) ) for _ in range(N) ] 

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

t=0	
for a,b in AB:
	t+=a
	if b<t:
		print "No"
		quit()
else:
	print "Yes"

Solution (Python):
n = input()
l = []
for i in range(n):
	a, b = map(int, raw_input().split())
	l.append((b, a))
curtime = 0
l.sort()
for i in l:
	if curtime + i[1] > i[0]:
		print "No"
		exit(0)
	else:
		curtime += i[1]
print "Yes"

Solution (Python):
n = input()
l = []
for i in range(n):
	a, b = map(int, raw_input().split())
	l.append((b, -a))
curtime = 0
l.sort()
for i in l:
	if curtime - i[1] > i[0]:
		print "No"
		exit(0)
	else:
		curtime -= i[1]
print "Yes"

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

for tsumugi in range(n):
  in1, in2 = map(int, input().split(" "))
  temp = [in1, in2]
  ab.append(temp)
  
ab.sort(key = lambda x : x[1])

a_sum = 0
ans = "Yes"

for matsuri in range(n):
  a_sum += ab[matsuri][0]
  if a_sum > ab[matsuri][1]:
    ans = "No"
    break

print(ans)

Solution (Python):
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x : x[1])
import numpy as np
a = np.cumsum([i[0] for i in ab])
b = np.array([i[1] for i in ab])
if sum(a<=b) == n:
  print("Yes")
else:
  print("No")

Solution (Python):
import numpy as np

N = int(input())

hyo = np.zeros((N,2))

for NN in range(N):
    hyo[NN] = input().split(' ')

hyo_sorted = hyo[np.argsort(hyo[:,1])]

tooktime = hyo_sorted[:,0].cumsum()

timeup = hyo_sorted[:,1]

if any(tooktime > timeup) ==True:
    print("No")
else:
    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])
t=0
cnt=0
for i in l:
    cnt+=1
    a,b=i
    t+=a
    if(t>b):
        print("No")
        break
    elif cnt==N:
        print("Yes");

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

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

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

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

print('Yes')

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

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

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

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    a,b = LI()
    BA[i] = (b,a)

BA.sort()

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

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

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

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

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    a,b = LI()
    BA[i] = (b,a)

BA.sort()
part_A = [0 for i in range(N)]
for i in range(N):
    B,A = BA[i]
    part_A[i] = A + part_A[i-1]

for i in range(N):
    B,A = BA[i]
    if B - part_A[i] < 0:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

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

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

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    a,b = LI()
    BA[i] = (b,a)

BA.sort()
part_A = [0 for i in range(N)]
for i in range(N):
    B,A = BA[i]
    part_A[i] = A + part_A[i-1]

for i in range(N):
    B,A = BA[i]
    if B - part_A[i] < 0:
        print("No")
        break
else:
    print("Yes")

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys

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

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

N = int(input())
BA = [[] for i in range(N)]
for i in range(N):
    A,B = LI()
    BA[i] = [B,A]


BA.sort()
part_A = [0 for i in range(N)]
for i in range(N):
    B,A = BA[i]
    part_A[i] = A + part_A[i-1]

for i in range(N):
    B,A = BA[i]
    if B - part_A[i]>= 0:
        pass
    else:
        print("No")
        break
else:
    print("Yes")

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

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

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

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

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

ab.sort(key=lambda x: x[1])
now = 0 
for i in range(n):
    now = now + ab[i][0]
    if now > ab[i][1]:
        print('No')
        sys.exit()

print('Yes')

Solution (Python):
n = int(input());
array = [[0]*2 for i in range(n)];
for i in range(n) :
	s = input().split(" ");
	array[i][0] = int(s[0]);
	array[i][1] = int(s[1]);
array.sort(key=lambda x:x[1]);
time = 0;
can = 1;
for i in range(n) :
	time += array[i][0];
	if time > array[i][1] :
		can = 0;
if bool(can) :
	print('Yes');
else :
	print('No')

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

ab.sort(key=lambda x: x[1])
now = 0 
for i in range(n):
    now = now + ab[i][0]
    if now > ab[i][1]:
        print('No')
        sys.exit()

print('Yes')

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

def main():
    N = int(input())
    tasks = [tuple(map(int, input().split())) for _ in range(N)]
    tasks.sort(key=itemgetter(1))
    start = 0

    for task in tasks:
        if start + task[0] > task[1]:
            print('No')
            return
        start += task[0]

    print('Yes')
    return

if __name__ == '__main__':
    main()

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

print(ans)

Solution (Python):
N = int(input())
lis = []
for _ in range(N):
    a, b = map(int, input().split())
    dic = {}
    dic["a"] = a
    dic["b"] = b
    lis.append(dic)
lis_sort = sorted(lis, key=lambda x:(x["b"], x["a"]))
t = 0
for dic in lis_sort:
    t += dic["a"]
    if t > dic["b"]:
        print("No")
        exit()
print("Yes")

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

Solution (Python):
def main():
	N = int(input())
	SE = [0]*(N)
	for i in range(N):
		SE[i] = list(map(int, input().split()))
	SE.sort(key=lambda x: (x[1], -x[0]))
	time_passsed = 0
	finish_possilbe = True
	for i in range(N):
		time_passsed += SE[i][0]
		if time_passsed > SE[i][1]:
			finish_possilbe = False
			break
	if finish_possilbe:
		print("Yes")
	else:
		print("No")



if __name__ == '__main__':
	main()

Solution (Python):
from operator import itemgetter
N = int(input())

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

lst.sort(key=itemgetter(1))

now = 0
flg = True
for item in lst:
    now += item[0]
    if now > item[1]:
        flg = False
        break

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

Solution (Python):
from operator import itemgetter
n = int(input())

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



abn.sort(key = itemgetter(1) )




ts = 0 
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

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

Solution (Python):
from operator import itemgetter
n = int(input())

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



abn.sort(key = itemgetter(1) )




ts = 0 
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

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

Solution (Python):

n = int(input())

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



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




ts = 0 
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

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

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

Solution (Python):
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
A.sort(key=lambda x:x[1])
count = 0
for a, b in A:
  count += a
  if count > 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])
time = 0
for a, b in AB:
    time += a
    if time > b:
        print('No')
        quit()

print('Yes')

Solution (Python):
import numpy as np

def main():
    n = int(input())
    ab = np.zeros([n, 2], dtype=int)
    for i in range(n):
        ab[i] = list(map(int, input().split(' ')))

    so = np.argsort(ab[:, 1], axis=0)
    count = 0
    ok = True
    for i in so:
        count += ab[i][0]
        if count > ab[i][1]:
            ok = False
            break

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

if __name__ == "__main__":
    main()

Solution (Python):
from itertools import accumulate

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


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


tB = accumulate(AB, lambda x, y: (x[0] + y[0], y[1]))

yes = all(t <= b for t, b in tB)
print('Yes' if yes else 'No')

Solution (Python):

"""
D - Megalomania
https://atcoder.jp/contests/abc131/tasks/abc131_d

"""
import sys


def solve(N, tasks):
    ct = 0
    tasks.sort(key=lambda x: x[1], reverse=True)

    while tasks:
        a, b = tasks.pop()
        ct += a
        if ct > b:
            return 'No'
    return 'Yes'


def main(args):
    N = int(input())
    tasks = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, tasks)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

sums = 0
flag = True
for i in range(N):
   sums += ab[i][0]
   if sums > ab[i][1]:
      flag = False

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

Solution (Python):
N = int(input())
joblist = [[int(s) for s in input().split()] for i in range(N)]
joblist_sorted = sorted(joblist, key=lambda x: x[1])
task = 0
flg = 'Yes'
for i in range(N):
  A, B = joblist_sorted[i]
  task = task + A
  if task > B:
    flg = 'No'
print(flg)

Solution (Python):



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

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

work.sort()

time = 0

is_ok = True

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

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

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

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

is_ok = True
spend = 0
for a, b in AB:
    spend += a
    if spend > b:
        is_ok = False
        break


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

Solution (Python):

"""
D - Megalomania
https://atcoder.jp/contests/abc131/tasks/abc131_d

"""
import sys


from heapq import heappop, heappush

def solve(N, tasks):
    ct = 0
    hq = []
    for a, b in tasks:
        heappush(hq, (b, a))

    while hq:
        b, a = heappop(hq)
        ct += a
        if ct > b:
            return 'No'
    return 'Yes'


def main(args):
    N = int(input())
    tasks = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, tasks)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

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

keika_time = 0
for work in W:   
    if work[1] - keika_time <= 0:   
        print('No')
        break
    elif work[1] - keika_time  >= work[0]:
        keika_time += work[0]
    elif work[1] - keika_time  < work[0]:
        print('No')
        break
else:   
    print('Yes')

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]
    data.sort(key=lambda x: x[1])
    now_time = 0

    flg = 1
    for i in range(num):
        if now_time + data[i][0] <= data[i][1]:
            now_time += data[i][0]
        else:
            flg = 0
            break
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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

S = 0
ans = 'Yes'

L = sorted(range(N), key=lambda k: B[k])
for j in L:
	S += A[j]
	if S > B[j]:
		ans = 'No'
		break

print(ans)

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

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

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

Solution (Python):
n=int(input())
s=[list(map(int, input().split()))  for i in range(n)]
v=[]
r=[]
x=0
y=0
s.sort(key=lambda x:x[1])

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

Solution (Python):





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

  if ABn[0][0] > ABn[0][1]:
    return False

  for i in range(1,N):
    ABn[i][0] += ABn[i-1][0]
    if ABn[i][0] > ABn[i][1]:
      return False
  
  return True


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

Solution (Python):




from operator import itemgetter
N = int(input())
work = []

ans = True


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

sorted_work=sorted(work, key=itemgetter(1))

for jikan,shimekiri in sorted_work:
    t += jikan
    if t > shimekiri:
        print('No')
        exit()

print('Yes')

Solution (Python):

from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]
    data.sort(key=lambda x: x[1])
    now_time = 0

    flg = 1
    for i in range(num):
        if now_time + data[i][0] <= data[i][1]:
            now_time += data[i][0]
        else:
            flg = 0
            break
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

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

Solution (Python):

"""
Created on Sun Jun 23 09:58:39 2019

@author: Yamazaki Kenichi
"""

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

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

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

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

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

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

calc = 0

for i in range(len(L)) :
    A,B = L[i]
    calc += A
    if calc > B :
        ans = "No"
        break
else :
    ans = "Yes"

print(ans)

Solution (Python):
def solve(n, a, b):
    t = max(b)
    for a_, b_ in sorted(zip(a, b), key=lambda _:-_[1]):
        if t > b_:
            t = b_
        t -= a_
    return "No" if t < 0 else "Yes"

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

Solution (Python):
def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB = sorted(AB, key=lambda ab: (ab[1]))
    t = 0
    for ab in AB:
        t += ab[0]
        if ab[1] < t:
            print('No')
            return
    print('Yes')

main()

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

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

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

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

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[1])
t=0
for i in l:
    a,b=i
    t+=a
    if(t>b):
        print("No")
        break
else:
    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])
t=0
for i in l:
    a,b=i
    t+=a
    if(t>b):
        print("No")
        break
else:
    print("Yes")

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

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

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

now_time = 0
flag = True
for a,b in tasks:
  if now_time + a > b:
    flag = False
    break
  now_time += a
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
import numpy as np

N = int(input())

k = []
for i in range(N):
    a = input().split(" ")
    k.append([int(a[0]),int(a[1])])

k = sorted(k, key=lambda x: x[1])
sum_A = 0
sum_B = 0
flag = 0
for i in range(N):
    sum_A += k[i][0]
    sum_B = k[i][1]
    if sum_A > sum_B:
        print("No")
        flag = 1
        break
if flag == 0:
    print("Yes")

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

sum_ = 0

for a,b in list:
    sum_ += a
    if sum_ > b:
        print("No")
        exit()

print('Yes')

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


b=[['','','']for i in range(n)]
for i in range(n):   
    b[i][0]=a[i][1]
    b[i][1]=a[i][0]
    b[i][2]=a[i][1]
    

b.sort()
val1=0
flag=0

for i in range(n):
    val1+=b[i][1]
    if val1 > b[i][2]:
        flag=1
        
print('Yes' if flag==0 else 'No')

Solution (Python):
import sys
import numpy as np

n = int(input())
a, b = np.fromstring(sys.stdin.read(), dtype=np.uint32, sep=' ').reshape((n, 2)).T
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')

Solution (Python):
import sys
import numpy as np

n = int(input())
tasks = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2))
a = tasks[:, 0]
b = tasks[:, 1]
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')

Solution (Python):
import sys
import numpy as np

n = int(input())
a, b = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2)).T
i = b.argsort()
print('Yes' if (b[i] - np.add.accumulate(a[i]) >= 0).all() else 'No')

Solution (Python):
import sys
import numpy as np

n = int(input())
a, b = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2)).T
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')

Solution (Python):
import sys
import numpy as np

n = int(input())
a, b = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2)).T
i = b.argsort()
print('Yes' if (a[i].cumsum() <= b[i]).all() else 'No')

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

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

sum_work = 0
res = 'Yes'
for a, b in ab_list:
    sum_work += a
    if sum_work > b:
        res = 'No'
        break
print(res)

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

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

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

sum = 0
for cost, limit in ab:
    sum += cost
    if sum > limit:
        print('No')
        break
else:
    print('Yes')

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

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

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

sum = 0
for cost, limit in ab:
    sum += cost
    if sum > limit:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
n=int(input())
ab=[]
for i in range(n):
    a=[int(j) for j in input().split()]
    ab.append(a)

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

p=0
for i in range(n):
    p+=ab[i][0]
    if ab[i][1]<p:
        print("No")
        import sys
        sys.exit()

print("Yes")

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] = [B[i],A[i]]
C.sort()
time = 0

for i in range(len(C)):
    time += C[i][1]
    if C[i][0] < time:
        print("No")
        exit()
print("Yes")

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

if sum(map(lambda x: x[0], task)) > max(map(lambda x: x[1], task)):
    print("No")
else:
    task.sort(key=lambda x: x[1])
    time = 0
    judge = True
    for t in task:
        time += t[0]
        if time > t[1]:
            print("No")
            judge = False
            break
    if judge:
        print("Yes")

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

for s,t in g:
    time+=s
    if time>t:
        print("No")
        exit()
print("Yes")

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

time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

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

print(result)