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:
def main():
    n = int(input())
    ABs = [list(map(int, input().split())) for _ in range(n)]
    ABs = sorted(ABs, key=lambda x: x[1])
    Count = 0
    for AB in ABs:
        Count += AB[0]
        if Count > AB[1]:
            print("No")
            exit()
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())

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

Sum = 0

for i in range(N):
    Sum = Sum + L[i][1]
    if Sum <= L[i][0]:
        continue
    else:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

Solution code:
class Work:
    require = 0
    limit = 0
    def __init__(self, require, limit) -> None:
        self.require = require
        self.limit = limit

def from_list(xs) -> Work: 
    return Work(xs[0], xs[1])

N = int(input())

works = [from_list([int(_) for _ in input().split()]) for i in range(N)]

def solve(works):
    works.sort(key=lambda x: x.limit)
    acc = 0
    for w in works:
        acc += w.require
        if acc > w.limit:
            return "No"
    return "Yes"

print(solve(works))

Submission status: Accepted

Solution code:
N = int(input())

Works = [dict(zip(["require", "limit"], [int(_) for _ in input().split()])) for i in range(N)]

def solve(Works):
    Works.sort(key=lambda x: x["limit"])
    acc = 0
    for w in Works:
        acc += w["require"]
        if acc > w["limit"]:
            return "No"
    return "Yes"

print(solve(Works))

Submission status: Accepted

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

for a,b in W:
    t+=a
    if t>b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
num = int(input())
work = []
for i in range(num):
    work.append(list(map(int,input().split(' '))))
work.sort(key = lambda a: a[1])
time = 0
limit  = 0
cant_flg = 0
for w in work:
    limit = w[1]
    time += w[0]
    if(limit<time):
        print('No')
        cant_flg = 1
        break
if(cant_flg==0):
    print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque
import heapq

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    A = []
    for i in range(N):
        a, b = NMI()
        A.append([a, b])
    A.sort(key=lambda x: x[1])
    t = 0
    for a in A:
        t += a[0]
        if t > a[1]:
            print("No")
            exit()

    print("Yes")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

time_cnt = 0
flag = True
for work in works:
    t = work[0]
    l = work[1]
    time_cnt += t
    if time_cnt > l:
        flag = False
        break
        
if flag:
    print('Yes')
else :
    print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cur = 0
for a,b in W:
  if cur+a > b:
    print("No")
    exit()
  cur += a 

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
AB = [LI() for _ in range(N)]
AB = sorted(AB, 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:
import math

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

jt = 0
for a, b in ab:
    jt += a
    if b < jt:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

time = 0

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

Submission status: Accepted

Solution code:
N = int(input())

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

time = 0

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

Submission status: Accepted

Solution code:
N = int(input())
works = []
time = 0
for _ in range(N):
    cost, deadline = map(int, input().split())
    works.append((deadline, cost))

works.sort()
# print(works)

for item in works:
    deadline, cost = item[0], item[1]
    # print(deadline)
    # print(cost)
    time += cost
    if time > deadline:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    jobs = []
    time = 0
    for _ in range(N):
        A, B = map(int, input().split())
        jobs.append((A, B))

    jobs = sorted(jobs, key=lambda x: x[1])
    for j in jobs:
        time += j[0]
        if time > j[1]:
            print("No")
            return
        
    else:
        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((a, b))

    A = sorted(A, key=lambda x: x[1])
    time = 0
    for a, b in A:
        time += a
        if time > b:
            return 'No'

    return 'Yes'

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

Submission status: Accepted

Solution code:
import numpy as np
# 締切が早いものから処理
N = int(input())
AB = np.array([[int(x) for x in input().split()] for _ in range(N)])
A = AB[:,0]
B = AB[:,1]
idx = B.argsort()
A = A[idx]
B = B[idx]
np.cumsum(A, out = A)
bl = (A <= B).all()
answer = 'Yes' if bl else 'No'
print(answer)

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


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

    AB.sort(key=lambda x: x[1])
    asum = [0 for _ in range(N + 1)]
    for i in range(N):
        asum[i + 1] = asum[i] + AB[i][0]

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

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for i in range(N):
    Q.append(tuple(map(int, input().split())))

Q = sorted(Q, key=lambda x: x[1])
now = 0
for i in range(N):
    if now + Q[i][0] <= Q[i][1]:
        now += Q[i][0]
    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])
A, B = [list(i) for i in zip(*AB)]
t = 0
bl = True
for i in range(N):
    t += A[i]
    if t > B[i]:
        bl = False

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

Submission status: Accepted

Solution code:
from sys import exit

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

job.sort(key=lambda x: x[1])
time = 0
for a, b in job:
    time += a
    if time > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N=int(input())

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(2)] for i in range(N)]

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


T=sorted(S,key=lambda x:x[1])
goukei=0

for i in range(N):
    simekiri=T[i][1]
    goukei+=T[i][0]
    if goukei>simekiri:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
ab = [LI() for _ in range(n)]
ab_s = sorted(ab, key=lambda x: x[1])
coll_t = 0
ans = 'Yes'
for a, b in ab_s:
    coll_t += a
    if coll_t > b:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)
def f(heap):
	t = 0
	while(heap):
		nd,d = heapq.heappop(heap)
		gap = nd - t - d
		if gap < 0:
			return False
		t += d
		
	return True
print 'Yes' if f(heap) else 'No'

Submission status: Accepted

Solution code:
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)
#(deadline, duration)
def f(heap):
	t = 0
	while(heap):
		nd,d = heapq.heappop(heap)
		gap = nd - t 
		gap -= d
		t += d
		while(heap and heap[0][0] == nd):
			_,v = heapq.heappop(heap) 
			t += v
			gap -= v
		if gap < 0: return False
	return True
print 'Yes' if f(heap) else 'No'

Submission status: Accepted

Solution code:
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)

def f(heap):
	t = 0
	while(heap):
		nd,ct = heapq.heappop(heap)
		while(heap and heap[0][0] == nd): ct += heapq.heappop(heap)[1]
		gap = nd - ct - t
		if gap < 0:
			return False
		while(heap and heap[0][1] <= gap):
			u,v = heapq.heappop(heap)
			gap -= v
			t += v
		t += ct
	return True
print 'Yes' if f(heap) else 'No'

Submission status: Accepted

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

Submission status: Accepted

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

def resolve():
    def main():

        n=int(input())
        l=[list(map(int,input().split())) for i in range(n)]
        l.sort(key=lambda x:x[1])
        time=0
        for x,y in l:
            time+=x
            if time>y:
                return 'No'
        return 'Yes'
    print(main())

resolve()

Submission status: Accepted

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

for i in ab:
    t += i[0]
    if i[1] < t:
        break
else:
    ans = 'Yes'

print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

n = int(readline())
ts = []
for i in range(n):
    a, b = map(int, readline().split())
    ts.append((b, a))
ts = sorted(ts, key=lambda x:(x[0], -x[1]))

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

Submission status: Accepted

Solution code:
n = int(input())
ab = []
A = 0

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

ab.sort()

for j in range(n):
  A += ab[j][1]
  if A>ab[j][0]:
    print('No')
    exit()
    
print('Yes')

Submission status: Accepted

Solution code:

from operator import itemgetter
n = int(input())
t = [list(map(int,input().split())) for i in range(n)]

t.sort(key=lambda x: x[1])
cost = 0
for i in t:
    cost += i[0]
    if cost > i[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
BA = []
for _ in range(N):
    a, b = map(int, input().split())
    BA.append((b, a))
BA.sort()
time = 0
is_timeover = False
for i in range(N):
    b, a = BA[i]
    time += a
    if time > b:
        is_timeover = True
        break

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

Submission status: Accepted

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

time=0
for i in range(len(t)):
  time+=t[i][0]
  if time>t[i][1]:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ls = [[int(i) for i in input().split()] for j in range(N)]
now = 0
ls = sorted(ls,key=lambda x:x[1])
ans = 'Yes'
for l in ls:
    now += l[0]
    if now > l[1]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
AB = []
import collections
d_ba = collections.defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    d_ba[b] += a

time = 0
for b in sorted(d_ba):
    if time + d_ba[b] <= b:
        time += d_ba[b]
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

work = sorted([list(map(int,input().split())) for i in range(N)], key = lambda x: x[1])
dead = [w[1] - w[0] for w in work]

now = 0

for i in range(N):
  if now > dead[i]:
    ans = "No"
    break
  now += work[i][0]
else:
  ans = "Yes"

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
lst=[]
for i in range(N):
    lst.append(list(map(int,input().split())))
AB=np.array(lst).reshape(N,2).T
A = AB[0]
B = AB[1]
ind = B.argsort()
A = A[ind]
B = B[ind]
if np.all(A.cumsum() <= B):
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

cnt=l[0][1]
for i in range(n):
    if cnt>l[i][1]:
        cnt=l[i][1]
    cnt-=l[i][0]
if cnt>=0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: (x[1], -x[0]))
    d = 0
    for a, b in ab:
        d += a
        if d > b:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
N = int(input())
job = [[0]*2 for i in range(N)]
time = 0
for i in range(N):
    l = list(map(int, input().split()))
    job[i][0], job[i][1] = l[1], l[0]
job = sorted(job)
for i in range(N):
    time += job[i][1]
    if time > job[i][0]:
        print("No")
        break
    elif i == N-1:
        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 x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][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 = sorted(lis, key = lambda x:x[1])
a = 0
for j in range(N):
    a += lis[j][0]
    if a > lis[j][1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()

N = ini()
tasks = []
for i in range(N):
    a, b = inm()
    tasks.append((b, a))
tasks.sort()


def solve():
    t = 0
    for b, a in tasks:
        if t + a > b:
            return False
        t += a
    return True


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
q = [[int(i) for i in input().split()] for j in range(N)]
q = sorted(q, key=lambda x: x[1])

time = 0
for i in range(N):
    a, b = q[i]
    time += a
    if time > b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys


if __name__ == "__main__":
    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
    for i in range(n):
        if time + ab[i][0] <= ab[i][1]:
            time += ab[i][0]
        else:
            print("No")
            sys.exit()
    print("Yes")

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A =[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append((a,b))

now =0
A_sort =sorted(A,key=lambda x: x[1])
for  progress,deadline in A_sort:
    now +=progress
    if now <=deadline:
        ans ="Yes"
    else:
        ans ="No"
        break
print(ans)

Submission status: Accepted

Solution code:
from heapq import heapify,heappop,heappush

N = int(input())
task_list = []#締め切り、所要時間
heapify(task_list)
for i in range(0,N,1):
    a,b = map(int,input().split())
    heappush(task_list,[b,a])

now_time = 0
while len(task_list)>0:
    b,a = heappop(task_list)
    now_time += a
    if now_time > b:
        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])

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

Submission status: Accepted

Solution code:
N, *AB = map(int, open(0).read().split())
AB = [(B, -A) for A, B in zip(AB[::2], AB[1::2])]
AB.sort()
t = 0
for b, a in AB:
    a = -a
    t += a
    if t > b:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())

tasks = []

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

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

time = 0
task_over = False
for i in range(N):
    tmp = dq.popleft()
    time += tmp[0]
    if time > tmp[1]:
        task_over = True
        break

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

Submission status: Accepted

Solution code:
N=int(input())
works=[]
for _ in range(N):
    A,B=map(int,input().split())
    works.append([B,A])
n_works=sorted(works)
answer=0
number=0
for work in n_works:
    number+=work[1]
    if number>work[0]:
        answer=1
        break
if answer==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

A.sort(key=lambda x:x[1])    
count = 0
for i in range(N):
    count += A[i][0]
    if count > A[i][1]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

    abl.sort(key=lambda x:x[1])
    curr_time = 0
    for curr_ab in abl:
        # print(curr_time)
        a,b = curr_ab
        curr_time += a
        if curr_time > b:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
ab = [0]*n
for i in range(n):
    ab[i] = list(map(int,input().split()))
ab.sort(key= lambda val : val[1])
ans = 1
t = 0
for i in range(n):
    t += ab[i][0]
    if ab[i][1] < t:
        ans = 0
if ans == 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

Jobs.sort(key=lambda x: x[1], reverse=True)
#print(Jobs)
now = Jobs[0][1]
for time, deadline in Jobs:
    if now < deadline:
        now -= time
    else:
        now = deadline
        now -= time
    #print(now)
if now < 0:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
def cumsum(a):
    s = [0]
    for i in range(len(a)):
        s.append(s[i]+a[i][0])
    return s

n = int(input())
a_b = [list(map(int,input().split())) for _ in range(n)]
a_b = sorted(a_b,key=lambda x: x[1])
#print(a_b)
all = cumsum(a_b)
#print(all)
flag = 1
for i in range(n):
    if all[i+1] > a_b[i][1]:
        flag = 0
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys

N = int(input())
tasks = sorted([list(map(int,input().split())) \
        for _ in range(N)],key = lambda x:(x[1]))
time = 0

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
from collections import namedtuple
Task = namedtuple('Task',('time','limit'))
tasks=[]
import operator
for _ in range(n):
    tasks.append(Task(*map(int, input().split())))
tasks.sort(key=operator.attrgetter('limit'))

total=0
for task in tasks:
    total+=task.time
    if total > task.limit:
        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 ab: ab[1], reverse=True)
time = ab[0][1]
for [a, b] in ab:
    time = min(time, b)
    time -= a
    if time < 0:
        print("No")
        exit(0)

print("Yes")

Submission status: Accepted

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

for i in range(n):
    ai, bi = map(int, input().split())
    jobs.append([ai, bi])

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

ans = "Yes"
limit = 0
time = 0
for job in jobs:
    time += job[0]
    limit = job[1]
    if limit < time:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

ans = "Yes"
time = 0
AB = sorted(ab, key=lambda x: x[1])

for x in AB:
    time += x[0]
    if time > x[1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
AB=n3(n)
AB.sort(key=lambda x:x[1])

time=0
f=True
for a,b in AB:
    time+=a
    if time<=b:
        pass
    else:
        f=False
        break
p0(f)

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])
total=0
a=True
for i in range(N):
    total+=B[i][0]
    if total>B[i][1]:
        print("No")
        a=False
        break
if a==True:
    print("Yes")

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    tasks = sorted(zip(B, A))
    cum = 0
    for bi, ai in tasks:
        cum += ai
        if cum > bi:
            print(NO)
            return
    print(YES)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    t = 0
    f = False
    for i, j in c:
        t += i
        f = f or t > j

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    t = 0
    for i, j in c:
        t += i
        if t > j:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    d, f = zip(*c)
    for i, j in zip(accumulate(d), f):
        if i > j:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())

    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    d, f = zip(*c)
    
    g = all(i <= j for i, j in zip(accumulate(d), f))
    print('Yes' if g else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))
    *d, = map(lambda x: x[0], c)
    *f, = map(lambda x: x[1], c)
    t = list(accumulate(d))
    g = all(i <= j for i, j in zip(t, f))
    print('Yes' if g else 'No')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from collections import deque
    n, *ab = map(int, open(0).read().split())
    c = list(zip(*[iter(ab)] * 2))
    c.sort(key=lambda x: (x[1], x[0]))

    c = deque(c)
    t = 0
    while c:
        d, f = c.popleft()
        t += d
        if f < t:
            print('No')
            break
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
n = int(input())
q = []
for _ in range(n):
    a, b = map(int, input().split())
    heappush(q, (b, a))

time = 0
while q:
    deadline, cost = heappop(q)
    time += cost
    if deadline < time:
        print('No')
        break
else:
    print('Yes')