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



Sample input:
5
2 4
1 9
1 8
4 9
3 12


Sample output:
Yes

Submission status: Accepted

Solution code:
N = int(input())

task = []

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

task.sort()

T = 0

for i in range(N):
    b = task[i][0]
    a = task[i][1]

    T+= a
    if T>b:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_list.append([a, b])
a_list.sort(key=lambda x: x[1])
temp = 0
ans = "Yes"
for i, j in a_list:
    temp += i
    if temp <= j:
        continue
    else:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for i in range(N):
  a, b = map(int, input().split())
  AB += [[a,b]]
  
AB.sort(key=lambda x: x[1])
time_used = 0
over_flag = 0
for i in range(N):
  a, b = AB[i]
  time_used += a
  if time_used > b:
    over_flag = 1
    
if over_flag:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

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

t = 0
clear = True
for b, a in sorted(BA):
    t += a
    if t > b:
        clear = False
        break

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
AB = [LIST() for _ in range(N)]

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

sum_time = 0
for A, B in AB:
	sum_time += A
	if sum_time <= B:  # 間に合う
		continue
	else:
		print("No")
		break
else:
	print("Yes")

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
loo = []

for i in range(n):
    a,b = na()
    loo.append([b,a])

loo = sorted(loo)

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

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
works = [tuple(map(int, input().split())) for i in range(N)]
works.sort(key=lambda x:x[1])

now = 0
ans = "Yes"
for i in range(N):
    now += works[i][0]
    if(works[i][1]<now):
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

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

lim = 0
ok = True
for i in range(N):
    lim += task[i][0]
    if lim > task[i][1]:
        ok = False
        break
    if not ok:
        break
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
n = getN()

works = []
for i in range(n):
    works.append(getList())

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

ans = "Yes"
tmp = 0
for w in works:
    tmp += w[0]
    # print(tmp,w[0], w[1])
    if tmp > w[1]:
        ans = "No"

print(ans)
# print(works)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append((b,a))
AB.sort()
last = 0
for i in range(N):
    if last+AB[i][1]<=AB[i][0]:
        last +=AB[i][1]
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
T=[]
append=T.append
for i in range(n):
  a,b=map(int,input().split())
  append([a,b])
T.sort(key=lambda x:x[1])
chk=True
t=0
for i in range(n):
  a,b=T[i]
  t+=a
  if t>b:
    chk=False
print("Yes" if chk==True else "No")

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

from operator import itemgetter
N = ii()
ABs = sorted([tuple(mi()) for _ in range(N)], key=itemgetter(1))

timesum = 0
for a, b in ABs:
  timesum += a
  if timesum>b:
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

accA = 0
for A, B in ABs:
    accA += A
    if accA > B:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append([x,y])

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    data = list(sorted(zip(B, A)))
    curr = 0
    for i in range(N):
        b, a = data[i]
        curr += a
        if curr > b:
            no()
            return
    yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
ab = [IL() for i in range(N)]

ab.sort(key=itemgetter(1))

num = 0
for a,b in ab:
  num += a
  if num > b:
    print("No")
    exit()
else:
  print("Yes")

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

L = []

N = int(input())
for i in range(N):
	A, B = getlist()
	L.append([B, A])

L = sorted(L)

judge = "Yes"
s = 0
for i in range(N):
	s += L[i][1]
	if L[i][0] < s:
		judge = "No"
		break

print(judge)

Submission status: Accepted

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

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

now = 0
comp = True
for a,b in ab_list:
    now += a
    if now > b:
        comp = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
L = []
i = 0
while i < n:
    a,b = map(int,input().split(' '))
    L.append((b,a))
    i += 1
L.sort()
sum_a = 0
f = 0
for l0 in L:
    sum_a += l0[1]
    if l0[0] < sum_a:
        f = 1
        break
if f == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
taskList = []
for x in range(N):
    ABtuple = tuple(map(int, input().split()))
    taskList.append(ABtuple)

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

Judge = True
time = 0

for x in taskList:
    time += x[0]
    if time > x[1]:
        Judge = False
        break

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
aa = []
bb = []
for k in range(n):
    a, b = list(map(int, input().split()))
    aa.append(a)
    bb.append(b)

# aa =     [384, 1725, 170, 4, 2, 578, 702, 143, 1420, 24, 849, 76, 85, 444, 719, 470, 1137, 455, 110, 15, 368, 104, 3, 366, 7, 610, 152, 4, 292, 334]
# bb = [8895, 9791, 1024, 11105, 6, 1815, 3352, 5141, 6980, 1602, 999, 7586, 5570, 4991, 11090, 10708, 4547, 9003, 9901, 8578, 3692, 1286, 4, 12143, 6649, 2374, 7324, 7042, 11386, 5720]
# n = len(aa)

aa = np.array(aa)
bb = np.array(bb)

must_start = bb - aa

s = np.argsort(bb)

must_start = must_start[s]
must_end = bb[s]
aa = aa[s]
ruikei_end = np.cumsum(aa)
must_end  >= ruikei_end

if (must_end  >= ruikei_end).all() == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


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


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, AB):
    AB.sort(key=lambda x: x[1])
    c = 0
    for a, b in AB:
        if c + a <= b:
            c += a
        else:
            return 'No'
    
    return 'Yes'


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

task_list = []

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

s = 0
for i in range(n):
    s += task_list[i][1]
    task_list[i][1] = s

task_list = [ i[0] >= i[1] for i in task_list ]

if all(task_list):
    ans = "Yes"
else:
    ans = "No"
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
BA = []
for _ in range(N):
    A, B = map(int, input().split())
    BA.append([B, A])

BA.sort()

now = 0
for a in BA:
    now += a[1]
    if now > a[0]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
task = [[int(x) for x in input().split()] for i in range(n)]
task.sort(key=lambda x:x[1])
check = True;time = 0
for i in range(n):
    t,f = task[i]
    time += t
    if time <= f:continue
    else:check = False;break
if check:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

X.sort(key=lambda x: (x[1], x[0]))
cnt = 0
for a, b in X:
    if cnt + a <= b:
        cnt += a
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(A, B, raw):
    now = 0
    for i in raw:
        now += A[i]
        if now > B[i]:
            print('No')
            return
    print('Yes')
    return


N = int(input())
A, B = {}, {}
for i in range(N):
    A[i], B[i] = map(int, input().split())
raw = []
for k, v in sorted(B.items(), key=lambda x: x[1]):
    raw.append(k)

check(A, B, raw)

Submission status: Accepted

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

total = 0
for a, b in arr:
  total += a
  if b < total:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

# print(ab_array)
time = ab_array[0][1]

for ab in ab_array:
    time = min(ab[1],time)
    time -= ab[0]
    if time < 0:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

e = []
for _ in range(N):
    a, b = map(int, input().split())
    e.append((b - a, a, b))  # (間に合う最終着手時間、所要時間、締め切り)

e.sort(key=itemgetter(2))
# print(e)
bl = True
cur = 0
for t, a, b in e:
    if cur <= t:
        cur += a
    else:
        bl = False
        break
print('Yes' if bl else 'No')

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N = i_inpl()
L = []

for _ in range(N):
    ab = l_inpl()
    L.append(ab)

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

t = 0
flag = True
for a, b in L:
    t += a
    if t > b:
        flag = False

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

Submission status: Accepted

Solution code:
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort(key=lambda x:x[1])
l=[]
tmp=0
for i in range(n):
    tmp+=ab[i][0]
    l.append(tmp)

f=False
for i in range(n):
    if l[i]>ab[i][1]:
        f=True

print("YNeos"[f::2])

Submission status: Accepted

Solution code:
N = int(input())

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

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

calc = 0

ans = "Yes"

for i in range(len(L)) :
    a,b = L[i]
    calc += a
    if calc > b :
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

inputs = [[int(elm) for elm in input().split(" ")] for i in range(N)]
inputs = sorted(inputs, key=lambda x: x[::-1])

#print(inputs)

out = "Yes"
tmp = 0
for A, B in inputs:
    tmp += A
    if tmp > B:
        out = "No"
        break

print(out)

Submission status: Accepted

Solution code:
n = int(input())
ab = [0] * n
for i in range(n):
  ab[i] = [int(j) for j in input().split()]
ab.sort(key=lambda x: x[1])
t = 0
for i in ab:
    t += i[0]
    if t > i[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
lis = []
for i in range(N):
    a,b = Is()
    lis.append([b,a])
lis = sorted(lis)
t = 0
for e in lis:
    t += e[1]
    if e[0] < t:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache, reduce

import numpy as np
from operator import itemgetter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
AB.sort(key=itemgetter(1))

A, B = zip(*AB)
A = np.array(A).cumsum()
B = np.array(B)

if all(A <= B):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

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

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

t = 0
canDone = True
for _ab in ab:
    t += _ab[0]
    if t > _ab[1]:
        canDone = False
        break
if canDone:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

N=int(input())
a = []
for i in range(N):
    l = tuple(map(int,input().split()))
    a.append(l)
a = sorted(a, key= lambda x: (x[1],x[0]) )
sm = 0
f = True
for aa in a:
    x,y = aa
    sm += x
    if sm > y:
        f = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])
ans = 'Yes'
time = 0
for A, B in AB:
    time += A
    if time <= B:
        continue
    ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=[]
for i in range(n):
    a,b = map(int, input().split())
    arr.append([a,b,i])
arr=sorted(arr, key=lambda x: x[0], reverse=True)
arr=sorted(arr, key=lambda x: x[1])
#print(arr)

task=0
ti=0
flag=0
for i in arr:
    task+=i[0]
    ti=i[1]
    #print(task,ti)
    if task > ti:
        flag=1
        break

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n = int(input())
ab = []
for _ in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))

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

Submission status: Accepted

Solution code:
N = int(input())

works_rev = []
for loop in range(N):
    a, b = list(map(int, input().split()))
    works_rev.append((b, a))

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
lines = sys.stdin.readlines()

works = [None]*n
_ = 0
for l in lines:
    works[_] = tuple(map(int, l.split(" ")))
    _ += 1

works.sort(key=lambda w:w[1], reverse=True)


time = 9999999999999999999999999
for i,w in enumerate(works):
    time = min(time,w[1]) - w[0]

print("Yes" if time >= 0 else "No")

Submission status: Accepted

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
cur = 0
for a, b in ab:
  cur += a
  if cur>b:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
AB=list(list(map(int,input().split()))for _ in range(N))
AB.sort(key= lambda x:x[1])
t=0
for a,b in AB:
    t+=a
    if not (t<=b):
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
import numpy as np

N = int(sys.stdin.readline())
ind = np.fromstring(sys.stdin.read(), dtype='i8', sep=' ').reshape((N, 2))
a = ind[:, 0]
b = ind[:, 1]
arg = np.argsort(b)
a = a[arg]
b = b[arg]
ac = np.add.accumulate(a)
if np.all(b - ac >= 0):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n=int(input())
job=[]
for i in range(n):
    a,b=map(int,input().split())
    job.append((a,b))
job=sorted(job,key=lambda x : x[1])
# print(job)
load=0
for cost,limit in job:
    load+=cost
    if load>limit:
        print("No")
        import sys 
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    jobs = []
    for i in range(n):
        a,b = map(int,input().split())
        jobs.append((b,a))

    jobs.sort()

    time = 0

    for i in jobs:
        time += i[1]
        if time > i[0]:
            print('No')
            return

    print('Yes')


main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())

task = [[] for _ in range(N)]
for i in range(N):
    a,b = [int(z) for z in input().split()]
    task[i] = [b,a]

task.sort()

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

print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter


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

info = sorted(info, key = itemgetter(1))
sum1 = 0
for i in range(n):
    sum1 += info[i][0]
    if sum1 > info[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

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

AB.sort(key=itemgetter(1))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    for i in range(3):
        if s[i] == s[i + 1]:
            print("Bad")
            return
    print("Good")
    return

#B
def B():
    n, l = LI()
    lis = [l + i for i in range(n)]
    s = sum(lis)
    a = inf
    for i in lis:
        if abs(a) > abs(i):
            a = i
    print(s-a)
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    def lcm(a, b):
        return a * b // gcd(a, b)
    a, b, c, d = LI()
    x = b // c - (a-1) // c
    y = b // d - (a-1) // d
    z = b // lcm(c , d) - (a-1) // lcm(c , d)
    print(b-a+1-(x+y-z))
    return

#D
def D():
    n = II()
    ab = LIR(n)
    ab.sort(key=lambda x: x[1])
    now = 0
    for a, b in ab:
        now += a
        if now <= b:
            continue
        print("No")
        return
    print("Yes")
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
ab = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
now = 0
for t in ab:
    now += t[0]
    if now > t[1]:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
tasks = []
for i in range(n):
    aa,ba = map(int,input().split())
    tasks.append([aa,ba])

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

now = 0
ok = 1
for i in range(n):
    now += tasks[i][0]
    #print(now,tasks[i][1])
    if now > tasks[i][1]:
        ok = 0

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l,key=itemgetter(1))
f=0
ct=0
for i in range(n):
  x=l[i][1]
  ct+=l[i][0]
  if ct>x:
    f=1
    break
if f==1:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N = II()
    AB = []
    for _ in range(N):
        AB.append(LI())

    # Bi の小さい順（締切の早い順）にソート O(NlogN)
    AB.sort(key=lambda x: x[1])

    current_time = 0
    for i in AB:
        current_time += i[0]
        if current_time > i[1]:
            print('No')
            return
    print('Yes')


main()

Submission status: Accepted

Solution code:
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
import time
import sys
from pprint import pprint
import itertools
import fractions

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

fail = False
now = 0
for ab in AB:
    a = ab[0]
    b = ab[1]
    now += a
    if now > b:
        fail = True
        break

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

Submission status: Accepted

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

AB.sort(key = lambda x:x[1])
ans = 'Yes'
time = 0

for n in range(N):
    time += AB[n][0]
    if time>AB[n][1]:
        ans = 'No'
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Python code to sort the tuples using second element 
# of sublist Function to sort using sorted() 
def Sort(sub_li): 

	# reverse = None (Sorts in Ascending order) 
	# key is set to sort using second element of 
	# sublist lambda has been used 
	return(sorted(sub_li, key = lambda x: x[1]))	 

n=int(input())
l=[]
for i in range(0,n):
    p=input().rstrip().split(' ')
    D=[]
    D.append(int(p[0]))
    D.append(int(p[1]))
    l.append(D)
l=Sort(l)
t=0;
G=0;
for i in range(0,len(l)):
    t=t+int(l[i][0])
    if t<=int(l[i][1]):
        continue;
    else:
        G=1;
        break;
if G==0:
    print("Yes")
else:
    print("No")