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

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

t = 0
ans = "Yes"

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lis = [list(map(int, input().split())) for i in range(N)]
lis.sort(key = lambda x: x[1])
time = 0
flag = 1
for i in range(N):
  time += lis[i][0]
  if time > lis[i][1]:
    flag = 0
    print('No')
    break
if flag == 1:
  print('Yes')

Submission status: Accepted

Solution code:
import os, sys, re, math, queue

N = int(input())
jobs = []
for _ in range(N):
	A,B = list(map(int,input().split(' ')))
	jobs.append((A,B))

jobs = sorted(jobs, key = lambda x: [x[1],-x[0]])
t = 0
ret = 'Yes'
for j in jobs:
	t += j[0]
	if t > j[1]:
		ret = 'No'
		break

print(ret)

Submission status: Accepted

Solution code:
n = int(input())
jobs = []
for _ in range(n):
    jobs.append(list(map(int, input().split())))
    
jobs.sort(key=lambda x:x[1]) #Bをkeyにソート
time = 0
result = 'Yes'

for job in jobs:
    time += job[0]
    if(time > job[1]):
        result = 'No'
        break
print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  AB = sorted([tuple(map(int, input().strip().split())) for _ in range(n)], key=lambda x:x[1])
  time = 0
  for a, b in AB:
    time += a
    if time > b:
      print('No')
      return
  print('Yes')

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
BAs = []
for n in range(N):
    A, B = [int(s) for s in input().split(' ')]
    BAs.append((B, A))
BAs.sort()
time = 0
count = 0
for B, A in BAs:
    time += A
    if time > B:
        break
    else:
        count += 1
if count == N:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import os, sys, re, math

N = int(input())
AB = []
for i in range(N):
    AB.append([int(n) for n in input().split()])

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

result = 'Yes'
t = 0
for ab in AB:
    t += ab[0]
    if t > ab[1]:
        result = 'No'
        break

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ok(ab):
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            return False
    return True

n = int(input())
print('Yes' if ok(sorted([list(map(int, input().split())) for _ in range(n)], key=lambda ab: ab[1])) else 'No')

Submission status: Accepted

Solution code:
import sys
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key= lambda x:x[1])
time = 0
for i in ab:
    time += i[0]
    if time <= i[1]:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

for i in range(n):
    if total+work[i][0] > work[i][1]:
        cnt += 1
        break
    else:
        total += work[i][0]

if cnt==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import numpy as np

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

timing = 0
is_safe = True
for item in works[(works[:,1].argsort(0))]:
    time, limit = item
    timing += time
    if timing > limit:
        is_safe = False
        break
print("Yes" if is_safe else "No")

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
lis =sorted([list(map(int,input().split())) for _ in range(n)], key = itemgetter(1))
t = 0
ans = "Yes"
for i in lis:
    t += i[0]
    if t > i[1]:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = sorted([list(map(int,input().split())) for _ in range(n)], key = lambda z:z[1])
t = 0
ans = "Yes"
for i in lis:
    t += i[0]
    if t > i[1]:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_d
# 最適なのは締切が速い順から取り掛かること
import sys
from operator import itemgetter
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


N = read_a_int()
AB = read_tuple(N)
AB.sort(key=itemgetter(1))
jikoku = 0
for a, b in AB:
    jikoku += a
    if jikoku > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
w = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: x[1])
agg = 0
for c, t in w:
    agg += c
    if t < agg:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
d = {}
total = 0
for _ in range(N):
    a, b = map(int, input().split())
    d[b] = d.get(b, 0) + a
for t, c in sorted(d.items()):
    total += c
    if total > t:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
w = []
for _ in range(n):
    w.append(list(map(int,input().split())))
w.sort(key=lambda x:x[1])
now = 0
ans = "Yes"
for t in w:
    now += t[0]
    if now > t[1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

# 締切Bが大きい順にソート
work.sort(key=lambda x: x[1], reverse=True)
#print(work)

remain_time = work[0][1]
in_time = True

for i in range(N):
  # 現在時刻は制約厳しいほうを採用し、仕事を割り当てる
  remain_time = min(work[i][1], remain_time) - work[i][0]
  #print(i, remain_time)
  # 残り時間がマイナスになるなら失敗
  if remain_time < 0:
    in_time = False
    break

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

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
# import statistics
import heapq


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
n = getInputInt()
data = getSomeInputListInt(n)

data_sorted = sorted(data, key=lambda x:x[1], reverse=True)

lim = sys.maxsize
flg = True

for d in data_sorted:
    if lim > d[1]:
        lim = d[1]
    lim -= d[0]

    if lim<0:
        flg = False
        break

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ab = []
    for _ in range(n):
        ab.append(tuple(map(int, input().split())))
    sorted_ab = sorted(ab, key=lambda x: x[1])
    now = 0
    for a, b in sorted_ab:
        now += a
        if now > b:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = []
c = 0
for _ in range(n):
    a, b = map(int, input().split())
    s.append([b, a])
s.sort()
for i in range(n):
    c += s[i][1]
    if c > s[i][0]:
        c = -1
        break
if c != -1:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
AB=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1])
t=0
flag=False
for a,b in AB:
    t+=a
    if t>b:
        flag=True
print("No" if flag else "Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[1])

limit = 0

for i, j in ab:
    limit += i
    if j < limit:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

n = ni()
ab = nan(n)
d = [(ab[i][1], ab[i][0], ab[i][1] - ab[i][0]) for i in range(n)]
d.sort()

ok = True
c = 0
for i in range(n):
    b, a, p = d[i]
    if p < c:
        ok = False
        break
    c += a

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

Submission status: Accepted

Solution code:
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:
        continue
    else:
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=LLIN(N)
    AB.sort(key=lambda x: x[1])

    now = 0    
    for a,b in AB:
        now += a
        if now > b:
            print("No")
            return
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=[]
for i in range (N):
	A.append(list(map(int,input().split())))
C=sorted(A,key=lambda A: A[1])
tmp=0
count=0
for i in range (N):
  tmp+=C[i][0]
  if tmp<=C[i][1]:
    count+=1
  else:
    print("No")
    break
if count==N:
  print("Yes")

Submission status: Accepted

Solution code:
from collections import OrderedDict
if __name__ == "__main__":
    n = int(input())
    job = dict()
    for i in range(n):
        tmp = list(map(int, input().split()))
        if tmp[1] in job:
            job[tmp[1]].append(tmp[0])
        else:
            job[tmp[1]] = [tmp[0]]

    sch = sorted(job)

    time = 0
    for j in sch:
        time += sum(job[j])
        if time <= j:
            continue
        else:
            print('No')
            exit()

    print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs = sorted(jobs, key=itemgetter(1))
total = 0
for a, b in jobs:
    total += a
    if total > b:
        print('No')
        exit()
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])

t = 0

can = False

for a, b in ab:
    t += a
    if t > b:
        break
else:
    can = True

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
from operator import itemgetter
input = sys.stdin.readline

N = int(input())
d = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    d[b] += a
task = list(d.items())
task.sort()

now = 0
ans = "Yes"
for limit, time in task:
    now += time
    if now > limit:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
a=sorted(a,key=lambda x:(x[1]))
#print(a)

time=0
for i in a:
    time+=i[0]
    if time>i[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
for _ in range(N):
  l, r = map(int, input().split())
  a.append((l, r))
a.sort(key = lambda x: x[1])
p = 0
for i in range(N):
  if p <= a[i][1] - a[i][0]: p += a[i][0]
  else:
    print("No")
    exit(0)
print("Yes")

Submission status: Accepted

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

now = cant = 0
for a, b in ab:
    now += a
    if now>b: cant = True
print("YNeos"[cant::2])

Submission status: Accepted

Solution code:
N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]
AB.sort(key=lambda x:x[1])

time = 0
flag = False
for i in range(N):
    time += AB[i][0]
    if time <= AB[i][1]:
        continue
    else:
        flag = True
        break

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
from itertools import accumulate

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
ab = list()
for _ in range(n):
    ab.append(na())

ab.sort(key=lambda x:x[1])
time = 0
for ai, bi in ab:
    time += ai
    if time > bi:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
L = [[int(l) for l in input().split()] for _ in range(N)]

from operator import itemgetter
L.sort(key=itemgetter(1))
time = 0
ans = "Yes"
for i in range(N):
    time += L[i][0]
    if time > L[i][1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

def solve():
    input = sys.stdin.readline
    N = int(input())
    W = [[int(w) for w in input().split()] for _ in range(N)]
    W.sort()
    W.sort(key = itemgetter(1))
    time = 0
    for i, w in enumerate(W):
        if time + w[0] > w[1]:
            print("No")
            break
        else:
            time += w[0]
    else: print("Yes")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort(key=lambda p: p[1])
    time = 0
    for a, b in AB:
        time += a
        if time > b:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda k: k[1])
t = 0

for Ai, Bi in AB:
    t += Ai
    
    if t>Bi:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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 accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()
task = [LIST() for _ in range(N)]
task = sorted(task, key=lambda x: (x[1], x[0]))
task = [list(x) for x in zip(*task)]

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

print("Yes")

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 accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()
task = [LIST() for _ in range(N)]
task = sorted(task, key=lambda x: x[1])
task = [list(x) for x in zip(*task)]

c = 0
for i in range(N - 1):
    if task[1][i] == task[1][i + 1]:
        c += 1
    else:
        if c != 0:
            task[0][i - c:i+1] = sorted(task[0][i - c:i+1])
            c = 0

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

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=True
now=0
for i in range(n):
    now+=ab[i][0]
    if now>ab[i][1]:
        ans=False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy


#X = str(input()).split()
#a = [int(x) for x in input().split()]


N = int(input())
AB=[]
A = []
B = []
C = []

for i in range(N):
  AB.append(str(input()).split())
  A.append(int(AB[i][0]))
  B.append(int(AB[i][1]))
  C.append([B[i]-A[i], A[i], B[i]])

C = sorted(C, key = lambda x: (x[2], x[0]))
unko = 1
time = 0

#print(C)

for i in range(N):
  if(C[i][2]-time-C[i][1]<0):
    print("No")
    unko = 0
    break
  else:
    time += C[i][1]

if(unko==1):
  print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

A = [0]*N
B = [0]*N

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


indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=itemgetter(1))
now=0
ans="Yes"
for i in ab:
    a,b=i[0],i[1]
    now+=a
    if now>b:
        ans="No"
        break

print(ans)

Submission status: Accepted

Solution code:
"""brute force
import itertools


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

for pattern in itertools.permutations([i for i in range(n)]):
    t = 0
    flag = True
    for i in pattern:
        t += jobs[i][0]
        if t > jobs[i][1]:
            flag = False
    if flag:
        print("Yes")
        exit()
print("No")
"""
import heapq

n = int(input())
jobs = [list(map(int, input().split()[::-1])) for _ in range(n)]

heapq.heapify(jobs)
t = 0
for i in range(len(jobs)):
    deadline, job_t = heapq.heappop(jobs)
    t += job_t
    if t > deadline:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([b,a])
l.sort()
tmp=0
for i in range(n):
  tmp+=l[i][1]
  if tmp>l[i][0]:
    print('No')
    break
  if i==n-1:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
from operator import itemgetter
N=int(input())
s=[tuple(map(int, input().split())) for i in range(N)]
s.sort(key=itemgetter(1))
t=0
for i in s:
    t+=i[0]
    if t>i[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

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

a = sorted(a, key=itemgetter(1))
work = 0
for i in range(N):
    work = work + a[i][0]
    if work > a[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
tasks = [list(map(int, input().split())) for i in range(n)]
tasks.sort(key=lambda x: x[1])

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

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=LLIN(N)
    AB.sort(key=lambda x: x[1])

    now = 0    
    for a,b in AB:
        now += a
        if now > b:
            print("No")
            return
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

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

time = 0

for task in tasks:
    time += task[0]

    if time > task[1]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

n, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])

def main():
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            return 'No'
    return 'Yes'

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab, key=lambda x: x[1])
arr = np.array(sorted_ab)
if np.any((arr[:, 1] - np.cumsum(arr[:, 0])) < 0):
  print('No')
else:
  print('Yes')

Submission status: Accepted

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

l.sort(key=lambda x:(x[1],-x[0]))
c = 0

for i,j in l:
    if c+i <= j:
        c += i
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
s = []
now = 0
simekiri = 0
flag = 0
for i in range(N):
    a,b = map(int,input().split())
    s.append([b,a])
s.sort()
for i in range(N):
    now += s[i][1]
    simekiri = s[i][0]
    if now>simekiri:
        print("No")
        flag = 1
        break
if flag == 0:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
works = []
for i in range(N):
    works.append(list(map(int, input().split())))
works = sorted(works, key=lambda x: (x[1], x[0]))
time = 0
isFail = False
for i in range(N):
    time += works[i][0]
    if time > works[i][1]:
        isFail = True
        break
print("YNeos"[isFail::2])

Submission status: Accepted

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

ab_li.sort(key=lambda x: x[1])
ab = []
a = 0
b = 0
h = 0
now = 0

for i in range(n):
    ab = ab_li[i]
    a = ab[0]
    b = ab[1]
    if b != h:
        h = b
    now += a
    if h < now:
        print("No")
        exit(0)

print("Yes")

Submission status: Accepted

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

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

if curtime <= i[1]:
  print("Yes")

Submission status: Accepted

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

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

count = 1
ans = 1
init = ab[0][0]
if ab[0][0] > ab[0][1]:
    ans = 0
for i in range(1, n):
    if init <= ab[i][1]:
        init += ab[i][0]
        count += 1
        if init > ab[i][1]:
            ans = 0
            break
if ans == 0:
    print("No")
else:
    if count == n:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(key=lambda ab: -ab[1])
deadline = AB[0][1]
for a, b in AB:
  if b < deadline:
    deadline = b
  deadline -= a
if deadline < 0:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter

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

t = 0
for i, j in ab:
    t += i
    if t <= j:
        ans = "Yes"
    else:
        ans = "No"
        break

print(ans)

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])
time = 0
flag = True

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

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

Submission status: Accepted

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


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    for span, dead in AB:
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


if __name__ == "__main__":
    main()