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 i in range(n):
  task.append(list(map(int,input().split())))

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


total = 0
for j in range(n):
  total += task[j][0]
  if(total > task[j][1]):
    print("No")
    break
  if(j == n-1):
    print("Yes")

Submission status: Accepted

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A,B=[0]*N,[0]*N
    for i in range(N):
        A[i],B[i]=map(int,input().split())
    Bargsort=np.argsort(B)
    t=0
    for i in Bargsort:
        t+=A[i]
        if t>B[i]:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

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 a, b in tasks:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

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

t = 0
for a, b in J:
    if t + a > b:
        res = 'No'
        break
    else:
        t += a
else:
    res = 'Yes'

print(res)

Submission status: Accepted

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

time = 0
for x in task:
    time += x[0]
    if time > x[1]:
        ok = False
        break
if ok:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
l = []
current_time = 0


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

l.sort()

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

print('Yes')

Submission status: Accepted

Solution code:
N, = map(int, input().split())
As, Bs = [], []
for _ in range(N):
    A, B = map(int, input().split())
    Bs.append([B, A])
Bs.sort()
t = -1
r = "Yes"
for b, a in Bs:
    t += a
    if b > t:
        continue
    r = "No"
    break
print(r)

Submission status: Accepted

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

current_time = 0

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

print("Yes")

Submission status: Accepted

Solution code:
#m = imt(imput())
#L = list(map(imt, imput().split()))
import math
import sys

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

def aa(N,AB):
    clk = 0
    flg = True
    for i in range(N):
        clk += AB[i][0]
        if clk > AB[i][1]:
            flg = False
            break
    if flg:
        return "Yes"
    else:
        return "No"
print(aa(N,AB))

Submission status: Accepted

Solution code:
N = int(input())

AB = [[0, 0]]
for i in range(N):
  AB.append(list(map(int, input().split()))[::-1])

AB.sort()
ans = 'Yes'

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

print(ans)

Submission status: Accepted

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

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


time = 0
for i in ab:
    time += i[0]
    if time > i[1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

from operator import itemgetter
li=sorted(li, key=itemgetter(1), reverse=True)
li.append([None,0])
over=0
#print(li)
for i in range(n):
  #aがbの差を超過する場合は既存の超過分にプラス
  if li[i][1]-li[i+1][1]<=over+li[i][0]:
    over=abs((li[i][1]-li[i+1][1])-(over+li[i][0]))
  #超過しない場合は超過分を0にリセット
  else:
    over=0
  #print(li[i+1][1],li[i][1],li[i][0],over)

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

Submission status: Accepted

Solution code:
def main():
	n = int(input())
	# b = int(input())
	# a = list(map(int,input().split()))
	l = [list(map(int, input().split())) for _ in range(n)]
	# print(a)
	
	l_s = sorted(l, key=lambda x: x[1])
	# l_s = sorted(l, reverse=True, key=lambda x: x[1])
	# l_s = sorted(l)
	# print(l_s)
	# print(l_s)
	count = []
	for i in l_s:
		count.append(i[1])

	c_max = max(count)
	sime = 0
	out = 0
	for i in l_s:
		 sime += i[0]
		 # print("sime = {}".format(sime))
		 # print("l_s = {}".format(i))
		 if sime > i[1]:
		 	out = 1
		 	break
		# print("c_max is {}".format(c_max))
	if sime <= c_max and out == 0:
		print("Yes")
	elif out == 1:
		print("No")






if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab_sorted = sorted(ab, key=lambda x: x[1])

    sum_a = 0
    for a, b in ab_sorted:
        sum_a += a
        if b < sum_a:
            print('No')
            quit()
    print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*N
B = [0]*N
tasks = [list(map(int,input().split())) for i in range(N)]
tasks.sort(key = lambda x:x[1])
can = True
S = 0
for i in range(N):
    S += tasks[i][0]
    if tasks[i][1] < S:
        can = False
if can:print('Yes')
else:print('No')

Submission status: Accepted

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

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

print('Yes')

Submission status: Accepted

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

n=int(input())
jobs=sorted(list(list(map(int,input().split())) for _ in range(n)), key=lambda x: x[1])
time = 0
for job in jobs:
    time+= job[0]
    if time > job[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def calculate(list):
    current = 0
    for item in list:
        current += item[0]
        if current > item[1]:
            return False

    return True

N = int(input())

arr = []
for i in range(N):
    arr.append([int(s) for s in input().split(" ")])

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

result = calculate(arr2)

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

Submission status: Accepted

Solution code:
n=int(input())
w=[[]for i in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  w[i]=[a,b]
w.sort(key=lambda x: x[1])
dl=0
t=0
for a,b in w:
  t+=a
  dl=b
  if dl<t:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

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

d=LS[0][1]
i=0
while d>=0 and i<n:
	d=min(d,LS[i][1])
	d-=LS[i][0]
	i+=1

print('Yes' if d>=0 else 'No')

Submission status: Accepted

Solution code:
n = int(input())
cnt = 0
x = []
for _ in range(n):
    a, b = map(int, input().split())
    x.append([b, a])
x.sort()
for i in range(n):
    cnt += x[i][1]
    if cnt <= x[i][0]:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

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:
# import bisect
# import heapq
# import math
# import queue
import sys


def main():
    # 読み込み回数が多い場合
    input = sys.stdin.readline
    N = int(input())
    
    # heap queue
    h = []
    for i in range(N):
        A, B = map(int, input().split())
        h.append((B, A))
    h.sort()
	
    time = 0
    for B, A in h:
        time += A
        if B < time:
            print("No")
            sys.exit()
    
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# import bisect
import heapq
# import math
# import queue
import sys


def main():
    # 読み込み回数が多い場合
    input = sys.stdin.readline
    N = int(input())
    
    # heap queue
    h = []
    for i in range(N):
        A, B = map(int, input().split())
        heapq.heappush(h, (B, A))
	
    time = 0
    while len(h) > 0:
        B, A = heapq.heappop(h)
        time += A
        if B < time:
            print("No")
            sys.exit()
    
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    A.sort()
    time = 0
    for b, a in A:
        time += a
        if time > b:
            print('No')
            exit()

    print('Yes')    



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

Solution code:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [MAP() for _ in range(N)]

A.sort(key=lambda x: x[1])
# print(A)

time = 0
for a in A:
	work, limit = a
	time += work
	if time > limit:
		print('No')
		sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
works = [[int(x) for x in input().split()] for _ in range(n)]
for i in range(n): works[i][0], works[i][1] = works[i][1], works[i][0]
works.sort()
time = 0
judge = True
for i in range(n):
  time += works[i][1]
  if time > works[i][0]:
    judge = False
    break
if judge: print("Yes")
else: print("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])
time = 0

for i in range(n):
    time += ab[i][0]
    if time > ab[i][1]:
        ans = "No"
        break
else:
    ans = "Yes"

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],reverse = True)
time = ab[0][1]

for i in range(n):
    if time > ab[i][1]:
        time = ab[i][1]
    time -= ab[i][0]
else:
    if time >= 0:
        ans = "Yes"
    else:
        ans = "No"

print(ans)

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    ans = "Good"
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            ans = "Bad"
    print(ans)
    return

def examB():
    N, L = LI()
    ans = 0
    if L>=0:
        for i in range(N - 1):
            ans += (L + i + 1)
    else:
        for i in range(N):
            ans += (L+i)
        if L+N-1<0:
            ans -=(L+N-1)
    print(ans)
    return

def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
def lcm(x, y):
    return x * y // gcd(x, y)
def examC():
    A, B, C, D = LI()
    CD = lcm(C,D)
    ans = B - (B//C + B//D - B//CD) - ((A-1) - ((A-1)//C + (A-1)//D - (A-1)//CD))
    print(ans)
    return

def examD():
    N = I()
    AB = [LI() for _ in range(N)]
    AB.sort(key=lambda x:x[1])
    cur = 0; ans = "Yes"
    for a,b in AB:
        cur +=a
        if b<cur:
            ans = "No"
            break
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()

Submission status: Accepted

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

sm=0
for i in range(n):
      sm+=L[i][0]
      if L[i][1]<sm:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
n = int(input())
l = [[int(i) for i in input().split()] for i in range(n)] 
l = sorted(l, key=lambda x: x[1])  #[1]に注目してソート
t=0

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

Submission status: Accepted

Solution code:
from operator import itemgetter


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

    t = 0
    for i in range(N):
        t += AB[i][0]
        if t <= AB[i][1]:
            continue
        else:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import accumulate
from operator import itemgetter
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1))
def g():
    acc = 0
    for a, b in AB:
        acc += a
        yield acc <= b
print("Yes" if all(g()) else "No")

Submission status: Accepted

Solution code:
n = int(input())
l = []
answer = "Yes"
t = 0
for i in range(n):
    a, b = map(int,input().split())
    l.append([a,b])
d=sorted(l, key=lambda x:x[1])

for j in range(n):
    t = t + d[j][0]
    if t > d[j][1]:
        answer = "No"
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from operator import itemgetter

N = int(input())
AB = sorted([[int(i) for i in input().split()] for _ in range(N)], key=itemgetter(1))

time = 0
for a,b in AB:
    time += a
    if time <= b:
        continue
    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.sort(key=lambda x:x[1])
t=0
for a,b in ab:
  t+=a
  if b<t:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
jobs = []
for _ in range(N):
    A, B = map(int, input().split())
    jobs.append((B, A))
jobs.sort(reverse=True)
now = 10 ** 9
for b, a in jobs:
    if now < b:
        now -= a
    else:
        now = b - a
print("Yes" if now >= 0 else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
a=sorted([list(map(int,input().split())) for i in range(n)], key=itemgetter(1))
b=0
for i in a:
    b+=i[0]
    if b>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])
t=0
for i in range(n):
  t+=a[i][0]
  if t>a[i][1]:
    print("No")
    break
  elif i==n-1:
    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])
f=1
now=0
for i in range(n):
    now+=ab[i][0]
    if now>ab[i][1]:
        f=0
        break
if f:
    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()
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())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: -x[1])
deadline = float('inf')
for a, b in AB:
    deadline = min(deadline, b) - a
    if deadline < 0:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

suma = 0
c = 0
for i in range(N):
    suma += array[i][0]
    if suma > array[i][1]:
        c = 1
        break
if c == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from operator import itemgetter
from collections import deque
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = deque(sorted(AB,key = itemgetter(1)))
ans = "Yes"
time = 0
while len(AB) != 0:
    tmp = AB.popleft()
    time += tmp[0]
    if time > tmp[1]:
        ans = "No"
        break
print(ans)

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


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

Submission status: Accepted

Solution code:
import numpy as np
import sys

N = int(input())

A = []
B = []
for i in range(N):
    a1, b1 = map(int, input().split())
    A.append(a1)
    B.append(b1)
    
b = np.argsort(B)

aa = [0] * N
bb = [0] * N
for i in range(N):
    aa[i] = A[b[i]]
    bb[i] = B[b[i]]

wt = 0
for i in range(N):
    l = bb[i]
    wt += aa[i]
    if wt > l:
        print("No")
        sys.exit()
        
print("Yes")

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
#from scipy.misc import comb

MOD = 10**9+7

N = int(input())

A = []
for i in range(N):
    a = tuple(map(int, input().split()))
    A.append(a)
A = sorted(A,key=lambda x:x[1])

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

print("Yes")

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

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys

n = int(input())

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

ABs.sort(key=itemgetter(1))
# print(ABs)

cnt = 0
for i in range(n):
    cnt += ABs[i][0]
    if cnt > ABs[i][1]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

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

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

flag = True
time = 0
for task in X:
    if time + task[0] > task[1]:
        flag = False
        break
    time += task[0]

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())

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

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

t = 0
ans = 'Yes'
for A, B in AB:
    if t + A > B:
        ans = 'No'
        break
    else: t += A
    
print(ans)

Submission status: Accepted

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

t = 0
ans = 'Yes'
for A, B in AB:
    if t + A > B:
        ans = 'No'
        break
    else: t += A
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
L = [[int(i) for i in input().split()] for j in range(n)]
L = sorted(L, key=lambda x:x[1])
num = 0
for l in L:
  num += l[0]
  if num <= l[1]:
    continue
  else:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
w=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  w[i]=a,b
w=sorted(w,key=lambda x:x[1])
time=0
for i in range(len(w)):
  if w[i][1]>=time+w[i][0]:
    time+=w[i][0]
  else:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

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

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
ab = sorted(ab, key=lambda x:x[1])
now = 0
for i in range(N):
    now += ab[i][0]
    if ab[i][1] < now:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

# N = 仕事の数
N = int(input())
# AB[i][0] = 仕事iを終わらせるまでの時間
# AB[i][1] = 仕事の締め切りまでの時刻
AB = [list(map(int, input().split())) for _ in range(N)]

# 思考メモ
# 貪欲法1：締め切りの短いものから解いていく？

# Bで昇順にソートする
AB_sort = sorted(AB, key=itemgetter(1, 0))

out = "Yes"
count = 0
for i in range(N):
    count += AB_sort[i][0]
    if count > AB_sort[i][1]:
        out = "No"
        break

print(out)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab = sorted(ab, key=lambda x:x[1])
    now = 0
    for i in range (n):
        if now + ab[i][0] > ab[i][1]:
            print("No")
            return None
        else:
            now += ab[i][0]
    print("Yes")
    
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = []
for _ in range(N):
    temp = list(map(int, input().split()))
    A.append(temp)
A = sorted(A,key = lambda x : x[1])
time = 0
for i in A:
    time += i[0]
    if time > i[1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
table=[[]*2 for i in range(n)]
for i in range(n):
  table[i]=list(map(int,input().split()))
table=sorted(table,key=lambda x:x[1])
T=0
t=0
for i in range(n):
  T=table[i][1]
  t=t+table[i][0]
  if t>T:
    print("No")
    break
if i==n-1 and t<=T:
  print("Yes")

Submission status: Accepted

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

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

count = 0
for i in range(n):
    li_sorted[i][1] -= count
    count += li_sorted[i][0]
    
for i in li_sorted:
    if i[1] >= i[0]:
        continue
    elif i[0] > i[1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
for j in range(n):
    tmp=ab[j][1]
    ab[j][1]=ab[j][0]
    ab[j][0]=tmp
ans='Yes'
cnt=0
cnt1=0
ab.sort()
for k in range(n):
    cnt=ab[k][0]
    cnt1+=ab[k][1]
    if cnt1>cnt:
        ans='No'
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
works = [[]] * n
for i in range(n):
  a, b = map(int, input().split(' ')) # a = 時間, b = 締め切り
  works[i] = [a, b]

ans = 'Yes'
sorted_works = sorted(works, key=lambda x: x[1]) # 締切の早い順にソート
total = 0

for work in sorted_works:
  total += work[0]
  if total > work[1]:
    ans = 'No'
    break
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

W=[[int(_) for _ in input().split()] for __ in range(N)]  

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

sum = 0
flg = False

for i in range(N):
    sum += W[i][0]
    if (sum > W[i][1]):
        flg = True
        break

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

Submission status: Accepted

Solution code:
n = int(input())
work = [[int(j) for j in input().split(" ")] for i in range(n)]
work = sorted(work,key = lambda x:(x[1],x[0]))

time = 0
for work_time, limit_time in work:
    time += work_time
    if time > limit_time:
        print("No")
        break

else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n=int(input())

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

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

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

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])
now = 0
for a, b in AB:
    now += a
    if now > b:
        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])
t=[0]*n#iを終えた時の時間
t[0]=a[0][0]
for i in range(n-1):
    t[i+1]=t[i]+a[i+1][0]
judge=True
for i in range(n):
    if a[i][1]<t[i]:
        judge=False
print("Yes") if judge else print("No")

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

A = []
B = []

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


A = np.array(A)
B = np.array(B)

time = 0
ans = "Yes"
A = A[np.argsort(B)]
B = np.sort(B)
#print(A,B)
for i in range(N):
    time += A[i]
    #print(time, B[i])
    if time > B[i]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

count_time = 0
for AB in ABn:
    count_time += AB[0]
    if count_time <= AB[1]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

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


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	li=[]
	for i in range(n):
		a,b=map(int,input().split())
		li.append((a,b))
	li.sort(key=lambda x:x[1])
	
	ans="Yes"
	now=0
	for a,b in li:
		now+=a
		if now>b:
			ans="No"
			break
	
	print(ans)



if __name__ == '__main__':
	main()

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

ans = 'Yes'
t = 0

for a, b in AB:
    if t+a <= b: t += a
    else:
        ans='No'
        break

print(ans)

Submission status: Accepted

Solution code:
import heapq
N = int(input())
q = []
for _ in range(N):
	at,bt = map(int,input().split())
	heapq.heappush(q,[bt,at])

cond = True
cnt = 0
tmp = 0
for _ in range(N):
	d,c = heapq.heappop(q)
	cnt += (d - tmp)
	cnt -= c
	if cnt < 0:
		cond = False
		break
	tmp = d

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