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())
lists = []
limit = []
cost = [0 for _ in range(n)]
for i in range(n):
    a, b = (map(int,input().split()))
    lists.append([a,b])

lists.sort(key = lambda x:x[1])
sum_ = 0
for i in range(n):
    sum_ = sum_ + lists[i][0]
    if sum_ <= lists[i][1]:
        continue
    else:
        print('No')
        exit(0)
print('Yes')

Submission status: Accepted

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


sum_a = 0
ch_over = 1

for i in range(n):
    sum_a += task_lis[i][0]
    if task_lis[i][1] < sum_a:
        ch_over = 0
        break

if ch_over == 0:
    print("No")
else:
    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] = [int(x) for x in input().split()]

tasks = sorted(list(zip(a, b)), key=lambda x: x[1])

is_okay = True
sum = 0
for i in range(N):
    sum += tasks[i][0]

    if sum > tasks[i][1]:
        is_okay = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
tasks = sorted([[int(i) for i in input().split()] for _ in range(N)], key=lambda item: item[1])
 
s = 0
for task in tasks:
    s += task[0]
    if task[1] < s:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
sumarray=np.cumsum(z[0][::-1])[::-1]
for i in range(N):
  
  if min(left,z[1,i])<sumarray[i]:
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Submission status: Accepted

Solution code:

N  = int(input())

AB = []
time = 0

for _ in range(N):
    AB.append(list(map(int, input().split())))

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

for i in range(N):
    time += NewAB[i][0]

    if time > NewAB[i][1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

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

ans = "Yes"
 
k = 0
for i in range(N):
    k += A[B1[i]]
    if k > B[B1[i]]:
        ans = "No"
 
print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())
task = {}
tasks = []
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    tasks.append((B,A))
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
# for b in sorted(task.keys()):    
#     s += task[b]
#     if b<s:
#         print('No')
#         exit()

for (b,a) in sorted(tasks):
    s += a
    if b<s:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

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

s_w_l = list(map(lambda x: x[1], s_w))
s_w_c = list(map(lambda x: x[0], s_w))

import numpy as np
if all(np.cumsum(np.array(s_w_c)) <= np.array(s_w_l)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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


def yes_or_no():
    sorted_index = np.argsort(B)
    if A[sorted_index[0]] > B[sorted_index[0]]:
        return 0
    sum_A = [A[sorted_index[0]]]
    for i in range(1, N):
        next_num = sum_A[i-1] + A[sorted_index[i]]
        sum_A.append(next_num)
        if next_num > B[sorted_index[i]]:
            return 0
        
    return 1

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

Submission status: Accepted

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

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

isYes=True
s=0
for a in sortAB:
    s += a[0]
    if s > a[1]:
        isYes=False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(n):
    a,b = list(map(int,input().split()))
    lis.append([a,b])
lis.sort(key=lambda x:x[1])
ans = 0
time = 0
for item in lis:
    time += item[0]
    if time > item[1]:
        ans += 1

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [0 for x in range(N)]
    for i in range(N):
        A[i] = list(map(int, input().split(" ")))
    sortedA = sorted(A, key=lambda x: x[1])
    s = [0 for _ in range(N)]
    for i, x in enumerate(sortedA):
        if i == 0:
            s[i] = x[0]
        else:
            s[i] = s[i-1]+x[0]

        if s[i] > x[1]:
            return 'No'
    return 'Yes'


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
N = int(input())

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

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

sumW = 0
for a in aaa:
    sumW += a[0]
    if sumW > a[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.sort(key=lambda ab: ab[1])

t = 0
success = True
for i in range(n):
  t += ab[i][0]
  # print(t)
  dif = ab[i][1] - t
  if dif < 0:
    success = False
    break

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

Submission status: Accepted

Solution code:
N = int(input())
s = [list(input().split( )) for i in range(N)]
#print(s[1][0])
t = sorted(s, key=lambda x:int(x[1]), reverse = True)
#print(t)
count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  if int(t[i][1]) >= sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
    sum1 = sum1 - int(t[i][0])
if count == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
tasks = sorted([[int(i) for i in input().split()] for _ in range(N)], key=lambda item: item[1])

s = 0
for task in tasks:
    s += task[0]
    if task[1] < s:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re
import bisect

def main():
    #A, B, C, D = map(int, input().split())
    N = int(input())
    diff_list = []
    for i in range(N):
        A, B = map(int, input().split())
        diff_list.append((B, A))

    diff_list = sorted(diff_list, key=lambda x: x[0])

    t = 0
    for i in range(N):
        B, A = diff_list[i]
        t += A
        if t > B:
            print("No")
            return

    print("Yes")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n = int(input())

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

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

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# input
n = int(input())
data = []
for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b])

# processing
data.sort(key=lambda x: x[1])
tmp = 0
for j in range(n):
    tmp += data[j][0]
    if tmp > data[j][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
task = []
task_sum = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    task.append([a, b])
task_f = sorted(task, key=lambda x: x[1])

s = 0
flag = True
for i in range(n):
    if s + task_f[i][0] > task_f[i][1]:
        flag = False
        break
    s += task_f[i][0]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

for i in range(N):
    A,B=map(int,input().split())
    lst.append([A,B])
lst.sort(key=lambda x: x[1])

def judge(N):
    worktime=0
    for i in range(N):
        worktime += lst[i][0]
        if worktime > lst[i][1]:
            return('No')
        if (i+1)==N:
            return('Yes')        
print(judge(N))

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
ab = sorted([[int(i) for i in input().split()] for i in range(n)],key=itemgetter(1))
sum = 0
for a,b in ab:
    sum += a
    if sum > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
h = []
mx = 0
for i in range(n):
    x, y = readmi()
    heapq.heappush(h, (-y, -x))
    mx = max(mx, y)
while(h):
    y, x = heapq.heappop(h)
    x = -x
    y = -y
    if mx > y:
        mx = y
    mx -= x
    if mx < 0:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [0] * N
B = [0] * N
AB = [0] * N
BA = [0] * N
for i in range(N):
    A[i], B[i] = [int(x) for x in input().split()]
    BA[i] = [B[i], A[i]]
list.sort(BA)
t = 0
fail = 0
for n in range(N):
    t += BA[n][1]
    if t > BA[n][0]:
        fail = 1
        break
if fail:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
list = [list(map(int, input().split())) for i in range(n)]
newlist = sorted(list, key=lambda x:x[1])
x = 0
y = 0
for i in newlist:
	x += i[0]
	if x <= i[1]:
		continue
	else:
		y += 1
		break
if y == 0:
	print('Yes')
else:
	print('No')

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

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(n):
  lis.append(list(map(int,input().split())))
lis.sort(key = lambda tup:tup[1])
t = 0
for item in lis:
  t += item[0]
  if t >item[1]:
    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.sort(key=lambda x: x[1])
time=0
for a,b in AB:
    time+=a
    if time>b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
L = [[]]
for i in range(N):
    a,b=[int(i) for i in input().split()]
    L.append([a,b])
del L[0]
L = sorted(L, key=lambda x:(x[1]))

def main():
    time = 0
    for n in range(N):
        time += L[n][0]
        if time > L[n][1]:
            print("No")
            return
    print("Yes")
    return

main()

Submission status: Accepted

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

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

sum = 0

for i in range(n):
    if i == 0:
        a[i][0] += 0
    else:
        a[i][0] += a[i-1][0]
    sum += a[i][0]

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

Submission status: Accepted

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

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

    sum_all = 0
    count = 0

    for i in range(n):
        sum_all += data[i][0]

    if sum_all > int(data[-1:][0][1]):
        return "No"

    for i in range(n):
        count += data[i][0]
        if count > data[i][1]:
            return "No"

    return "Yes"

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

Submission status: Accepted

Solution code:
n = int(input())
# A = []
# B = []
AB = []

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

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

current = 0
ans = True
for i in range(n):
    time = AB[i][0]
    now = current + time

    if now <= AB[i][1]:
        current += time
        continue
    else:
        ans = False
        break

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

Submission status: Accepted

Solution code:
n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
'''for i in range(n):
  x = l[i][1] - l[i][0]
  l[i][2] = x'''
l.sort(key=lambda x: x[1])
#print(l)

check = []
c = 0
for i in range(n):
  if c != l[i][1]:
    check.append(l[i][1])
    c = l[i][1]
#print(check)

sum_t = 0
limit = l[0][1]
ans = 0
for i in range(n):
  if limit != l[i][1]:
    limit = l[i][1]
  sum_t += l[i][0]
  if sum_t > limit:
    ans += 1
#print(ans)
if ans == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
n=int(input())
ab=sorted([[int(i) for i in input().split()] for _ in range(n)],key=lambda x:x[1])
now=0
for a,b in ab:
    now+=a
    # print((a,b,now))
    if now>b:
        print("No")
        break
else:
    print("Yes" if now<=ab[-1][1] else "No")

Submission status: Accepted

Solution code:
from sys import exit

def sfn(a):
    return a[1]
    

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

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

As = []
Bs = []
ABs = []
for _ in range(N):
	A,B = map(int,input().split())
	As.append(A)
	Bs.append(B)
	ABs.append([A,B])
	
if max(Bs) < sum(As):
	print("No")
	exit()
else:
	ABs = sorted(ABs,key=lambda x: (x[1],x[0]))
	#print(ABs)
	sum1 = 0
	for i in range(len(ABs)):
		sum1 += ABs[i][0]
		if ABs[i][1] < sum1:
			print("No")
			exit()
	else:
		print("Yes")
		exit()
		
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
alllist = []
listtime = []
listtask = []
for i in range(N):
    a,b = map(int,input().split())
    alllist.append([a,b])
sortlist = sorted(alllist, key=lambda x: x[1])

a = 0

for i in range(N):
    a += sortlist[i][0]
    if a > sortlist[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

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

Submission status: Accepted

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

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

tasks.sort(key=lambda x:x[1])
costs = [a[0] for a in tasks]
deadLines = [b[1] for b in tasks]
sumCost = 0

for n in range(len(costs)) :
  sumCost += costs[n]
  dead = deadLines[n]
  if sumCost > dead :
    print("No")
    sys.exit()

print("Yes")

Submission status: Accepted

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

A = sorted(A, key=lambda x: x[1])
last = A[N-1][1]
si = 0
for i in range(N):
    si += A[i][0]
    if(si > A[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],x[0]))
time = 0
for A, B in AB:
    time += A
    if B < time:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import itertools
import sys

input = sys.stdin.readline


def main():
    # クリティカルパルかなんか？
    # 累積和つかう？
    # 仕事が期限までに終わらせるかどうか
    # ナーススケジューリング問題？
    # 締切とタスクの合計値
    # 累積和となんかやと思うんやがな…
    # うーん、答えがわからん
    N = int(input())
    task_list = sorted(
        [[int(i) for i in input().split()] for _ in range(N)], key=lambda x: x[1]
    )
    print(
        "Yes"
        if all(
            [
                j <= i[1]
                for i, j in zip(
                    task_list, itertools.accumulate(map(lambda x: x[0], task_list))
                )
            ]
        )
        else "No"
    )


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = []
b = []
w = {}
for _ in range(N):
    A,B = list(map(int,input().split()))
    a.append(A)
    b.append(B)
for i,c in enumerate(b):
    if not c in w.keys():
        w[c] =  [i]
    else:
        w[c].append(i)
#print(a)
#print(w)
wt = 0
for t in sorted(w.keys()):
    #print('clock:',t)
    #print(w[t])
    for k in w[t]:
        wt += a[k]
    else:
        pass
        #print(k,wt)
    if t >= wt:
        pass
    else:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())


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

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


sum = 0
flag = 0

for i in range(N):
    sum += work[i][0]
#    print("sum",sum)
    if(sum>work[i][1]):
        flag = 1
        break
    
if(flag==0):
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
H=[]
s=0
ans = 0

for i in range(N):
        H.append(list(map(int,input().split())))


H.sort(key=itemgetter(1))

for i in range(N):
    s += H[i][0]
    if H[i][1] < s:
        ans += 1
        break

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

Submission status: Accepted

Solution code:
N = int(input())
AB = []
asum = 0
bmax = 0
for n in range(N):
  a,b = [int(x) for x in input().split(' ')]
  asum += a
  if bmax <= b:
    bmax = b
  AB.append((a,b))
  
res = 'Yes'
if asum > bmax:
  res = 'No'
else:
  ABsort = sorted(AB,key=lambda x:x[1])
  t = 0
  for x in ABsort:
    a,b = x
    t += a
    if b < t:
      res = 'No'
      break
print(res)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
tasks=[list(map(int,input().split())) for i in range(N)]
able_finish = 'Yes'
time = 0
ts = tasks
ts.sort(key=lambda x:x[1])
for t in ts:
  time += t[0]
  #print(time,t[0],t[1])
  if time >t[1]:
    able_finish = 'No'
print(able_finish)

Submission status: Accepted

Solution code:
n = int(input())
task = []
for i in range(n):
    a = input().split(" ")
    task.append([int(a[1]), int(a[0])])
task.sort()
time = 0
out = 0
for j in range(n):
    time += task[j][1]
    if time > task[j][0]:
        out = 1
        break
if out == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

#print(ABlist)
ans = "Yes"
k = 0
for j in range(N):
    k += ABlist[j][0]
    if k > ABlist[j][1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(tuple(map(int,input().split(' '))))
    a_sorted = sorted(a,key=lambda x:x[1])
    job_time = 0
    end_time = 0
    for a,b in a_sorted:
        job_time += a
        end_time = b
        if job_time > end_time:
            return 'No'
    return 'Yes'

print(main())

Submission status: Accepted

Solution code:
A = int(input())
AB_list = [list(map(int, input().split())) for _ in range(A)]
#AB_list = sorted(AB_list,key=lambda a :(-a[1],-a[0]))
AB_list = sorted(AB_list,key=lambda a :(a[1],a[0]))
#sum = AB_list[0][0]
sumab = 0
#print(AB_list)

for i,ab in enumerate(AB_list):
    if i == 0:
        if ab[1] >= ab[0]:
            sumab = ab[0]
            continue
        else:
            print('No')
            exit(0)

    if sumab + ab[0] <= ab[1]:
        sumab += ab[0]
        #print(ab)
        #print(sumab,'presum','next1',i)
    else:
        #print(ab)
        #print(sumab,'presum','next2',i)
        print('No')
        exit(0)

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
BA = []
for i in range(N):
    A,B = map(int,input().split())
    BA.append([B,A])
BA.sort()
time = 0
fin = True
for i in range(N):
    time += BA[i][1]
    if time > BA[i][0]:
        fin = False
if (fin):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(out)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
AB = []
for i in range(N):
    ab = list(map(int,input().split()))
    AB.append(ab)
AB_matrix = np.array([AB])
A = AB_matrix[0]
AB_sort = A[np.argsort(A[:,1])]
now = 0
for j in AB_sort:
    now += j[0]
    if now <= j[1]:
        ans = 'Yes'
    else:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
#D問題
N = int(input())
work_list =[]
for i in range(N):
    A,B = map(int,input().split())
    work_list.append([A, B])
work_list.sort(key=lambda x:x[1])
count = 0
ans = "Yes"
for i in range(N):
    count = work_list[i][0]+count
    if count > work_list[i][1]:
        ans = "No"
        break;
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]#N×"2"の行列Dを作る
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):#i行目の成分を入力
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])#2列目の成分でソート

x=0
for i in range(0,N):
    x=x+D[i][0]#経過時間
    y=D[i][1]#締め切り時刻
    if x>y:
        n=1
        break
    else:
        n=0
if n==1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a=[]


for i in range(n):
    s,p=map(int,input().split())
    a+=[[s, p] ]
    

import operator as op
a.sort(key = op.itemgetter(1))


time=0
yyes=True
for i  in range(n):
    time+=a[i][0]
    if(time>a[i][1]):
        yyes=False
        break
    
if yyes:
    print("Yes")
else:
        print("No")

Submission status: Accepted

Solution code:
n=int(input())
# a=[[0]*2]*n
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
d=0
for i in range(n):
    d+=c[i]
    if b[i][0]<d:
        ans="No"
        break
print(ans)

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(key = itemgetter(1))
count = 0
for i in range(len(L)):
    if count + L[i][0] > L[i][1]:
        print('No')
        exit()
    else:
        count += L[i][0]
print('Yes')

Submission status: Accepted

Solution code:
import heapq
N = int(input())
q = []
time = 0
for x in range(N):
    A , B = map(int, input().split())
    task = (B , A)
    heapq.heappush(q, task)
for y in range(N):
    task = heapq.heappop(q)
    time += task[1]
    if time > task[0]:
        ans = "No"
        break
else:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

A=np.array(b)
c=A.argsort()

time=0

for i in range(n):
    time=time+a[c[i]]
    if time>b[c[i]]:
        print('No')
        break
    if i==n-1 and time<=b[c[i]]:
        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())
    
B_sort = sorted(range(len(B)), key=lambda k: B[k])
flag = True
time = 0
for i in B_sort:
    time += A[i]
    if time > B[i]:
        flag = False
        print('No')
        break

if flag:
    print('Yes')

Submission status: Accepted

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

stask = sorted(task, key = lambda x: x[1])
time = 0
for i in range(N):
    time += stask[i][0]
    if time > stask[i][1]:
        print('No')
        break
    if i == N-1:
        print('Yes')

Submission status: Accepted

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

ab.sort(key=lambda x:x[1])
s = 0
d = []
for i in ab:
    s = s + i[0]
    d.append((i[1],s))
ans = 'Yes'
for i in d:
    if i[0]<i[1]:
        ans = 'No'
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
T=0
A=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append([a,b])
A.sort(key=lambda x: x[1])

for i in range(N):
    T+=A[i][0]
    if A[i][1]<T:
        ans="No"
        break
    else:
        ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a_lst = []
b_lst = []

for i in range(0, n):
    a, b = [int(elem) for elem in input().split()]
    a_lst.append(a)
    b_lst.append(b)

tmp = zip(b_lst, a_lst)
tmp = sorted(tmp)
b_lst, a_lst = zip(*tmp)   

flag = 0
sums = 0
for i in range(0, len(a_lst)):
    sums += a_lst[i]
    if sums > b_lst[i]:
        flag = 1
        break

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

Submission status: Accepted

Solution code:
N=int(input())

AB=[]
sum_A=0
max_B=0
for _ in range(N):
  a,b=[int(x) for x in input().split()]
  AB.append((a,b))
  sum_A+=a
  max_B=max(max_B,b)
  
if max_B<sum_A:
  print("No")
else:
  sortedAB=sorted(AB,key=lambda x:(x[1],x[0]),reverse=True)
  t=sortedAB[0][1]
  for ab in sortedAB:
    if t > ab[1]:
      t=ab[1]
    t-=ab[0]
    if t < 0:
      print("No")
      break
  else:
    print("Yes")

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

n = int(input())

tasks = []

for _ in range(n):
  time, delivery = map(int, input().split())
  heappush(tasks, (delivery, time))

now = 0

for _ in range(n):
  delivery, time = heappop(tasks)
  now += time
  if now > delivery:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

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

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

def abc(a):
    time = 0
    for job in a:
        time += job[0]
        if time > job[1]:
            return 'No'
    return 'Yes'

print(abc(ls))

Submission status: Accepted

Solution code:
N=int(input())
AB=[0]*N
for i in range(N):
    A,B=map(int,input().split())
    AB[i]=[A,B]
    
AB.sort(key=lambda x:x[1])
nunc=0

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

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
tasks=[]
for i in range(N):
    ab = list(map(lambda x: int(x),input().split()))
    tasks.append(ab)

tasks.sort(key=lambda x: (x[1],-x[0]))
costs = [0]
for i in range(len(tasks)):
  costs.append(costs[-1]+tasks[i][0])
#print(tasks)
#print(costs)
x = np.array(tasks).T[1]
y = np.array(costs[1:])
ans = ""
#print(tasks)
#print(x)
#print(y)
if len(np.where(x-y<0)[0])>0:
    ans="No"
else:
    ans = "Yes"
print(ans)

Submission status: Accepted

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

work.sort()
# print(work)

sum = 0
time = 0

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

print('Yes')