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:
from collections import deque
import sys

n = int(input())

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

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

d = []
d = deque(d)
num = 0
while len(ab) > 0:
	d = deque([])
	d.append(ab.pop())
	while True:
		if len(ab) == 0:
			break
		if ab[-1][1] == d[0][1]:
			d.append(ab.pop())
		else:
			break
	for i in range(len(d)):
		a,b = d.pop()
		num += a
	if num > b:
		print('No')
		sys.exit()

print('Yes')

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
A = deque()
for _ in range(N):
    a,b = list(map(int,input().split()))
    A.append([b,a])
A = list(A)
A.sort()
time = 0
for i in A:
    time += i[1]
    if time > i[0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N=int(input())

works = []

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

    works.append([a,b])

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


flg = 0
for j in range(N):
    if j==0:
        if sorted_works[j][0]>sorted_works[j][1]:
            flg+=1
    else:
        sorted_works[j][0] += sorted_works[j-1][0]

        if sorted_works[j][0]>sorted_works[j][1]:
            flg+=1


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

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

time=0
for item in ba:
  b=item[0]
  a=item[1]
  #print(a,b,time)
  
  time+=a
  if time>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])
ans = "Yes"
t = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

#print(List)

i=0
time=0
while i<N:
    
    time+=List[i][0]
    
    if not time<=List[i][1]:
        print("No")
        quit()
    
    i+=1
    
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

t = [[0]*2 for i in range(N)]

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

t.sort()

#print(t)

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
work = [None] * n
for i in range(n):
    work[i] = tuple(map(int, input().split()))
work = sorted(work, key=lambda x: x[1])
t = 0
f = True
for i, w in enumerate(work):
    t += w[0]
    if t > w[1]:
        f = False
        break
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
A=[tuple(map(int,input().split())) for i in range(N)]
A.sort(key=lambda x: x[1])
a=0
b=0 
c=0 
for i in range(len(A)):
   a+=A[i][0]
   b=A[i][1]
   if a>b:
      c+=1
      print('No')
      break
if c==0:
  print('Yes')

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
AB = LIR(n)
AB.sort(key=itemgetter(1))
tmp = 0
for a, b in AB:
    if tmp + a <= b:
        tmp += a
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N = int(input())

    tasks = []
    for _ in range(N):
        tasks.append(tuple(map(int, input().split())))  # (A,B)
    tasks.sort(key=itemgetter(1))

    t = 0
    cond = True
    for a, b in tasks:
        t += a
        if t > b:
            cond = False
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int( input() )

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

Max = L[0][1]
for i, j in L:
  Max -= i + max( Max - j, 0 )
if Max >= 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# D - Megalomania

from operator import itemgetter

N = int(input())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB = sorted(AB, key=itemgetter(1), reverse=True)
deadline = AB[0][1]
for i in range(N):
    deadline = min(deadline, AB[i][1]) - AB[i][0]

print('Yes' if 0 <= deadline else 'No')

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    C = []
    for i in range(n):
        a, b = MI()
        C.append((a, b))
    C = sorted(C, key=lambda x:x[1])
    # print(C)

    ctime = 0
    for a, b in C:
        # print(a, b)
        ctime += a
        if ctime > b:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    solve()

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

ans = 'Yes'
present_time = 0
for ab in AB:
  present_time += ab[0]
  dead_line = ab[1]
  if present_time > dead_line:
    ans = 'No'
    break

print(ans)

Submission status: Accepted

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

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

for i in li:
  time += i[0]
  if i[1]<time:
    flag = 'No'
    break

print(flag)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import numpy as np
input = sys.stdin.readline


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


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    ab = sorted([list(readnums()) for _ in range(N)], key=itemgetter(1))
    a = np.cumsum(np.array(list(map(lambda x: x[0], ab))))
    b = list(map(lambda x: x[1], ab))
    for A, B in zip(a, b):
        if A > B:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque
import bisect
import sys
sys.setrecursionlimit(10**9)

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

    x = 0
    X.sort(key=lambda x: x[0])
    X = deque(X)
    l = len(X)
    for _ in range(l):
        b,a = X.popleft()
        # print(b,a,x)
        if x + a > b:
            print("No")
            exit()

        x += a

    print("Yes")



if __name__ == "__main__":
  main()

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])
jikoku=0
for i in range(n):
  jikoku+=ab[i][0]
  if jikoku>ab[i][1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#w = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(n)]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
now = 0

for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        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 = 'Yes'
time = 0
for ab in AB:
    a,b = ab[0], ab[1]
    time += a
    if time > b:
        ans = 'No'

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = 0
cnt = 0
for i in range(n):

    tmp += ab2[i][0]
    if tmp <= ab2[i][1]:
        cnt += 1
if cnt == n:
    print('Yes')
    exit()
print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

M = 0
for k,v in K:
    M += k
    if M > v:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
X=[0]*N
for i in range(N):
    X[i] = list(map(int, input().split()))
X.sort(key=lambda x:x[1])
def check():
    now = 0
    for i in range(N):
        now += X[i][0]
        if now > X[i][1]:
            return 'No'
    return 'Yes'
print(check())

Submission status: Accepted

Solution code:
N = int(input())
L = []

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

count = 0
frag = 0
for i in range(N):
    count += L[i][1]
    if count > L[i][0]:
        print("No")
        frag = 1
        break
if frag == 0:
    print('Yes')

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ab = [inpl() for _ in range(n)]
ab.sort(key=lambda x:x[1])
now = 0
for a,b in ab:
    now += a
    if now > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N=int(input())

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

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

for i in range(N):
    t=L[i]
    a,b=t
    if now+a<=b:
        now+=a
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
L = [tuple(map(int,input().split())) for i in range(N)]
X = sorted(L, key = lambda k:k[1])
cnt = 0
ans = True
for i,j in X:
    cnt += i
    if cnt > j:
        ans = False
        break
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1])
flag = 0
cur = 0
for i in range(N):
    a,b = A[i]
    cur += a
    if cur>b:
        flag = 1
        break
if flag==1:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
lis=[LI() for i in range(n)]
lis.sort(key=lambda x:x[1])
#print(lis)
time=0
for i in range(n):
    time+=lis[i][0]
    if time>lis[i][1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque

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

AB.sort(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())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[1],x[0])) 
t = 0
for s,b in a:
    t += s
    if t > b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
from operator import itemgetter
t = 0
ab = [list(map(int,input().split()))for i in range(n)]
ab.sort(key = itemgetter(1))
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    t += a
    if t > b:
        print('No')
        break
else:print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

jobs = []

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

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

time = 0

for i, j in jobs:
    time += i
    if time <= j:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    li=[]
    for i in range(N):
        ab=list(map(int,readline().split()))
        li.append(ab)
    
    li.sort(key=lambda x:x[1])
    t=0
    for i in range(N):
        task=li[i]
        t+=task[0]
        if t>task[1]:
            print("No")
            break
    else:
        print("Yes")
if __name__=="__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

C = zip(B, A)
C = sorted(C)
B, A = zip(*C)
ans = 1
t = 0
for i, j in zip(A, B):
    t += i
    if t <= j:
        continue
    else:
        print("No")
        ans = 0
        break
if ans:
    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
ok = True
for a,b in ab:
  t += a
  if t > b: ok = False
print("Yes" if ok 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])
t = 0
ans = 'Yes'
for i in range(N):
    t += AB[i][0]
    if t > AB[i][1]:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
ab = mylistinput(n)

ab = mysort(ab,1,False)
# print(ab)

t = 0
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    t += a
    if t<=b:
        pass
    else:
        print("No")
        exit()
print("Yes")
exit()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])

ans = "Yes"
t = 0
for a, b in AB:
    t += a
    if t > b:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[1]) #締め切りが早い順位ソート

tmp = 0
for a, b in AB:
    if tmp + a <= b:
        tmp += a
    else:
        print ('No')
        exit()

print ('Yes')

Submission status: Accepted

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

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

t=0
for a,b in l:
  t+=a
  if t>b:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

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

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
res = 'Yes'
A = [[0 for j in range(2)] for i in range(N)]
for i in range(N):
  A[i][0], A[i][1] = map(int, input().split(' '))
A.sort(key=lambda x: x[1])
A.append([0, 0])
total = 0
i = 0
while i < N:
  while True:
    total += A[i][0]
    if A[i][1] != A[i + 1][1]:
      break
    i += 1
  if A[i][1] < total:
    res = 'No'
    break
  i += 1
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())


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

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

Submission status: Accepted

Solution code:
import numpy as np
from itertools import accumulate

n = int(input())
aa = np.zeros(n, np.int64)
bb = np.zeros(n, np.int64)
for i in range(n):
    aa[i], bb[i] = list(map(int, input().split()))
asums = list(accumulate(aa))

cc = np.argsort(bb)
aa = [aa[c] for c in cc]
aa = np.array(list(accumulate(aa)))
bb.sort()
if (aa > bb).sum()>0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

import heapq
N = int(input())
tasks = []
heapq.heapify(tasks)
broke = False
cum = 0
for i in range(N):
    A,B = (int(x) for x in input().split())
    if A > B:
        print('No')
        broke = True
        break
    else:
        heapq.heappush(tasks,(B,A))
if broke == False:
    for i in range(N):
        temp = heapq.heappop(tasks)
        cum += temp[1]
        if cum > temp[0]:
            print('No')
            broke = True
            break
    if broke == False:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
def main():
    N = int(readline())
    tasks = np.array(read().split(), np.int64).reshape((-1, 2))
    tasks = tasks[np.argsort(tasks[..., 1]), ...]
    tasks[..., 0] = np.add.accumulate(tasks[..., 0], axis=0)
    if np.all(tasks[..., 1]-tasks[..., 0]>=0):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
def main():
    N = int(readline())
    tasks = np.array(read().split(), np.int64).reshape((-1, 2))
    tasks = tasks[np.argsort(tasks[..., 1]), ...]
    tasks[..., 0] = np.add.accumulate(tasks[..., 0], axis=0)
    if (tasks[..., 1]-tasks[..., 0]>=0).all():
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
t = 0
for i, j in sorted([list(map(int, input().split())) for _ in [0]*int(input())], key = lambda x:x[1]):
  t += i
  if t > j:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
def main():
    N = int(readline())
    tasks = np.array(read().split(), np.int64).reshape((-1, 2))
    tasks = tasks[np.argsort(tasks[..., 1]), ...]
    tasks[..., 0] = np.add.accumulate(tasks[..., 0], axis=0)
    tmp = tasks[..., 1]-tasks[..., 0]
    if np.all(tmp>=0):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from operator import itemgetter 
def main():
    N = int(readline())
    tasks = []
    for _ in range(N):
        a, b = map(int, readline().split())
        tasks.append((a, b))
    tasks.sort(key=itemgetter(1))
    time = 0
    for a, b in tasks:
        time += a
        if time > b:
            print('No')
            return  
    print('Yes')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#python3
from operator import itemgetter 
from itertools import accumulate
def main():
    n = int(input())
    d = []
    for _ in range(n):
        x, y = map(int, input().split())
        d.append((x, y))
    d.sort(key=itemgetter(1))
    acc = 0
    f = True
    for i in range(n):
        acc = acc+d[i][0] 
        if acc > d[i][1]:
            f = False
    if f:
        print('Yes')
    else:
        print('No')
main()

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []

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

C = list(zip(A,B))
C = sorted(C, key=lambda x:x[1])

time = 0
for a,b in C:
    time = time + a
    if time<=b:
        continue
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    tasks = list()
    for _ in range(N):
        A, B = list(map(int, input().split(' ')))
        tasks.append((B, A))
    tasks.sort()
    current = 0
    for t in tasks:
        dead_line_time, required_time = t
        if current + required_time > dead_line_time:
            print('No')
            exit(0)
        current += required_time
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = sorted(list(list(map(int,input().split())) for _ in range(n)), key=lambda x:x[1])
t = 0
amari = 0
for a,b in l:
  #print(a,b,t,amari)
  if b-t>=a:
    amari += (b-t)-a
    t = b
  else:
    if amari>=a-(b-t):
      amari -= a-(b-t)
      t = b
    else:
      print("No")
      exit()
 # print(a,b,t,amari)
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()
time=0
cnt=0
for i in range(n):
    time+=l[i][1]
    if time>l[i][0]:
        print("No")
        break
    else:
        cnt+=1
if cnt==n:
    print("Yes")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
A=[]
for _ in range(N):
    time_req,end=map(int, sys.stdin.readline().split()) #所要時間、締め切り
    A.append((end,time_req))
A.sort()

cur=0   #現在の時刻

for end,time_req in A:
    cur+=time_req
    if cur<=end:    #締め切りまでに仕事が終わる
        pass
    else:           #締め切りまでに仕事が終わらない場合
        print "No"
        quit()
else:
    print "Yes"

Submission status: Accepted

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

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

cnt = 0
for b, a in ab:
    cnt += a
    if cnt > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort(key=lambda x: x[1])
ans=0
t=0
for i in range(N):
 t+=lst[i][0]
 if t>lst[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")