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())
jobs = [0]*N
for i in range(N):
    a, b = map(int, input().split())
    jobs[i] = (a, b)

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

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

print("Yes")

Submission status: Accepted

Solution code:
import numpy as np

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

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

A = [x[0] for x in AB_sort]
B = [x[1] for x in AB_sort]

A_cum = np.array(A).cumsum()

for i in range(N):
    if A_cum[i] > B[i]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

    time = 0
    for i in range(N):
        a, b = works[i]
        time += a
        if time > b:
            print('No')
            return
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_d

import sys
# sys.setrecursionlimit(100000)
import heapq


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    """
    締切がはやい順に仕事を行う。
        全て完了できれば: Yes
        できなければ: No
    """
    n = input_int()
    hq = []
    for _ in range(n):
        a, b = input_int_list()
        heapq.heappush(hq, (b, a))
    t = 0
    while hq:
        b, a = heapq.heappop(hq)
        t += a
        if t > b:
            print("No")
            return
    print("Yes")
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

limit2time = []

for i in range(N):
    time, limit = map(int, input().split())

    limit2time.append((limit, time))

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

# print(limit2time)
cur = 0
for item in limit2time:
    # print(item)
    key, time = item
    if cur + time > key:
        print("No")
        break
    cur += time
else:
    print("Yes")

Submission status: Accepted

Solution code:
time=0
n=int(input())
todo=[]*n

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

todo.sort()
d=True

for i in range(n):
  time += todo[i][1]
  if todo[i][0]<time:
    d=False
    break

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    n = int(lines[0].strip())

    E = [list(map(int, lines[i].split())) for i in range(1, n+1)]
    E = sorted(E, key=lambda x: x[1])

    cur_t = 0

    for i in range(n):
        cur_t += E[i][0]
        if cur_t > E[i][1]:
            print('No')
            return

    print('Yes')

main()

Submission status: Accepted

Solution code:
N=int(input())
li=[]
ans="Yes"
t=0
for i in range(N):
    A,B=map(int,input().split())
    li.append([B,A])
li.sort()

for j in range(N):
    t+=li[j][1]
    if t<=li[j][0]:
        pass
    else:
        ans="No"
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

work = [[] for i in range(N)]

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

work.sort()
total = 0
for i in range(N):
    total += work[i][1]
    if total > work[i][0]:
        print('No')
        exit(0)
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])
now=0
for a,b in ab:
  now+=a
  if now>b:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    point = 0
    ab = []
    for i in range(int(input())):
        t = list(map(int, input().split()))
        ab.append(t)
    ab.sort(key=lambda x: x[1])
    for i in range(len(ab)):
        point += ab[i][0]
        # print(point, ab[i])
        if point > ab[i][1]:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    main()

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

check = True
sum_A = 0
for j in range(N):
  sum_A += BA[j][1]
  if sum_A > BA[j][0]:
    check = False
    break
    
print("Yes" if check else "No")

Submission status: Accepted

Solution code:
n = int(input())
task = []
for i in range(n):
    a,b = map(int,input().split())
    task.append([b,a])
sorted_task = sorted(task)
#print(sorted_task)
isOK = True
ans = 0
for i in range(n):
    ans += sorted_task[i][1]
    #print(sorted_task[i][0],ans)
    if ans > sorted_task[i][0]:
        isOK = False
        break
if isOK:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()

wt = []

for i in range(n):
    a, b = inintm()
    wt.append([a,b])

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

t = 0

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

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
T = []
for _ in range(N):
    T.append(tuple(map(int, input().split())))
T.sort(key=itemgetter(1))
A = [i[0] for i in T]
B = [i[1] for i in T]
sum = 0
for i in range(N):
    sum += A[i]
    if sum > B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N = int(input())
    tasks = []
    for _ in range(N):
        a, b = map(int, input().split())
        tasks.append((b, a))
    tasks.sort()
    t = 0
    for b, a in tasks:
        if t + a > b:
            break
        t += a
    else:
        print("Yes")
        exit(0)
    print("No")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(tuple([b,a]))
    A.sort()
    total = 0
    for a, b in A:
        total+=b
        if a < total:
            print('No')
            return
    print('Yes')
main()

Submission status: Accepted

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

ab.sort(key=lambda x: x[1])
for a, b in ab:
    now += a
    if now>b:
        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())

flag=True
sum=0
sorted_index=np.argsort(b)
for i in sorted_index:
  sum+=a[i]
  if sum>b[i]:
    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 _ in range(n)]
ab.sort(key = lambda x: x[1])
time = 0
ans = "Yes"
for i in range(n):
    time += ab[i][0]
    if time <= ab[i][1]:
        continue
    else:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from collections import Counter
from operator import itemgetter
from bisect import bisect_left, bisect
from decimal import *
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)


def main():
    n = int(input())
    arr = []
    for i in range(n):
        arr.append(list(map(int, input().split())))
    arr_sorted = sorted(arr, key=lambda x: x[1])

    now = 0

    for i in range(n):
        if now + arr_sorted[i][0] > arr_sorted[i][1]:
            print("No")
            return
        else:
            now += arr_sorted[i][0]
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
al = [list(map(int, input().split())) for _ in range(int(input()))]
al = sorted(al, key=lambda x: x[1])
s = 0
for i, j in al:
    s += i
    if s > j:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())

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

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

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

print("Yes")

Submission status: Accepted

Solution code:

N = int(input())
job = []
for i in range(N):
    a, b = map(int, input().split())
    job.append([a, b])
#print(job)
job.sort(key=lambda x: x[1])
#print(job)
for i in range(1, N):
    job[i][0] += job[i - 1][0]
for i in range(N):
    if job[i][0] > job[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
ab = [LI() for _ in range(n)]
ab.sort(key=itemgetter(1))
time = 0
for a, b in ab:
    time += a
    if time > b:
        print('No')
        quit()
print('Yes')

Submission status: Accepted

Solution code:
import itertools
n = int(input())
work_lst = []

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

work_lst.sort(key=lambda x: x[1])
work_acc = [i[0] for i in work_lst]
work_acc = itertools.accumulate(work_acc)
work_dead = [i[1] for i in work_lst]
for x, dead in zip(work_acc, work_dead):
    if x > dead:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

for i in range(n):
  a=list(map(int,input().split()))
  lst.append(a)
  
lst.sort(key=lambda x:x[1])

time=0

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

Submission status: Accepted

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

Submission status: Accepted

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

ab = zip(b,a)
ab = sorted(ab)
b,a = zip(*ab)

val = 0
ans  = "Yes"
for i in range(n):
    val +=a[i]
    if val > b[i]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
BA = []
for _ in range(N):
    a, b = map(int, input().split())
    BA.append([b, a])
BA.sort()
time=0
for i in range(N):
    time+=BA[i][1]
    
    if time>BA[i][0]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys

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

sum = 0

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

print('Yes')

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

#t=1
t=ii()
lol=[] 
ans=0
for _ in range(t):
    a,b=ml()    
    lol.append([b,a])
lol.sort()
f=0
for i in range(t):
    if(lol[i][1]+ans<=lol[i][0]):
        ans+=lol[i][1]
    else:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

#t=1
t=ii()
lol=[] 
ans=0
for _ in range(t):
    a,b=ml()    
    lol.append([b,a])
lol.sort()
f=0
for i in range(t):
    if(lol[i][1]+ans<=lol[i][0]):
        ans+=lol[i][1]
    else:
        f=1
        break
if f:
    print("No")
else:
    print("Yes")

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    Q=[]
    for _ in range(N):
        a,b=MI()
        Q.append([b,a])
        
    Q.sort()
    now=0
    flag=1
    for i in range(N):
        b,a=Q[i]
        now+=a
        if now>b:
            flag=0
            break
            
    if flag:
        print("Yes")
    else:
        print("No")
        

main()

Submission status: Accepted

Solution code:
n=int(input())
a=[]
b=[]
for _ in range(n):
    c=list(map(int,input().split()))
    a.append(c[0])
    b.append(c[1])
d=list(zip(b,a))
d.sort()
#print(d)

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A_list =[0]*N
B_list =[0]*N
for i in range(N):
    A_list[i],B_list[i] = map(int,input().split())
x = np.argsort(B_list)
A_list = np.array(A_list)[x]
B_list = np.array(B_list)[x]
ans = 0
for i,j in zip(A_list,B_list):
    ans +=i
    if(ans<=j):
        pass
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import numpy
N = int(input())
task = numpy.array([list(map(int, input().split())) for _ in range(N)])
task = task[numpy.argsort(task[:, 1])]

ans = 'Yes'

time = 0
for j in task:
    time += j[0]
    if time > j[1]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

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

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N = I()
    AB = sorted(LIR(N), key=lambda x: x[1])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
   N = int(input())
   T = [list(map(int, input().split())) for i in range(N)] 
   S = [[b, a] for a,b in T]
   U = sorted(S)
   time = 0
   for b, a  in U:
        time += a
        if time > b:
           print('No')
           return
   print('Yes')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

n=int(input())
ba=[[0]*2 for i in range(n)]
for i in range(n):
    ai,bi=map(int,input().split())
    ba[i]=[bi,ai]
    
ba.sort() 

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

Submission status: Accepted

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

Submission status: Accepted

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

W = sorted(W,key =lambda x:(x[1],x[0]))
now = 0
for w in W:
  #print(now,w[0])
  if now +w[0] > w[1]:
    print("No")
    exit()
  now+=w[0]
print("Yes")

Submission status: Accepted

Solution code:
from collections import deque
n = int(input())
task = deque()
now = 0
for i in range(n):
  task.append(tuple(map(int, input().split())))
task = deque(sorted(task, key = lambda x: x[1]))
while True:
  work = task.popleft()
  now+=work[0]
  if now>work[1]:
    print('No')
    break
  if len(task) == 0:
    print('Yes')
    break

Submission status: Accepted

Solution code:
N = int(input())
A = {}
B = []
for n in range(N):
    a,b = list(map(int,input().split()))
    B.append(b)
    
    if b not in A.keys():
        A[b] = [a]
    else:
        A[b].append(a)

B=list(set(B))
B.sort()

time=0
ans='Yes'
break_flag = False

for b in B:
    if break_flag:
        break
    for a in A[b]:
        time += a 
#         print(b,a,time)
        if b < time:
            ans='No'
            break_flag = True
            break
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]
AB_sorted = sorted(AB, key=lambda x: x[1])
task_sum = 0
ans = 'Yes'

for i in range(N):
  task_sum += AB_sorted[i][0]
  if task_sum > AB_sorted[i][1]:
    ans = 'No'
    break
print(ans)

Submission status: Accepted

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

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

flag = 1
total = 0

for i in lis:
    total += i[0]
    if total > i[1]:
        flag = 0
        break

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

Submission status: Accepted

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

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

flag = 1
total = 0

for i in lis:
    total += i[0]
    if total > i[1]:
        flag = 0
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
#n,m = map(int,input().split())

S={}
for i in range(n):
    a,b = map(int,input().split())
    if b in S:
        S[b]+=a
    else:
        S[b]=a
    
S2=sorted(S.items())
wa=0
for i in range(len(S2)):
    s,w = S2[i]
    wa+=w
    if s<wa :
        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])

s = 0

flag = True

for a, b in ab:
    s += a
    if s > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = list(zip(B, A))
C.sort()
B, A = zip(*C)
t = 0
for c in C:
    t += c[1]
    if t <= c[0]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

ab.sort(key = lambda x: x[1])
ok = True
last = 0
for a,b in ab:
    if b-a>=last:
        last += a
    else:
        ok = not ok
        break
print('Yes' if ok else 'No')

Submission status: Accepted

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

fin = 0
for j in range(n):
    fin += sorted_ab[j][0]
    if fin > sorted_ab[j][1]:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

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

for i in range(n):
    ai, bi = list(map(int, input().split()))
    tasks.append((ai, bi))

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

t = 0
for i in range(n):
    if t > tasks[i][1] - tasks[i][0]:
        print("No")
        exit()
    else:
        t += tasks[i][0]

print("Yes")

Submission status: Accepted

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

ans=0
ch=0

for c in range(n):
  x=a[c][0]
  y=a[c][1]
  
  ans+=x
  if ans>y:
    ch+=1
  
if ch==0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

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

schedule = sorted(schedule, key=lambda x: x[1])
ans = 0
end = 0

flg = True
for i in range(N):
    end += schedule[i][0]
    if end <= schedule[i][1]:                   # 重複がダメならば等号を消す
         continue
    flg = False

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

Submission status: Accepted

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

worklist.sort(key=lambda x: x[1])
timecount = 0
count = 0

for i in range(n):
    timecount += worklist[i][0]
    if timecount > worklist[i][1]:
        count += 1

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N=int(input())
ab=[tuple(map(int,input().split())) for _ in range(N)]
ab=sorted(ab, key=itemgetter(1))
#print(ab)

c=0
for v in ab:
    if c+v[0]<=v[1]:
        c+=v[0]
    else:
        print('No')
        break
else:
    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()

tm = 0
flg = True
for b, a in ba:
    if tm + a <= b:
        tm += a
    else:
        flg = False

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

Submission status: Accepted

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

Submission status: Accepted

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

print('Yes')

Submission status: Accepted

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

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])
t=0
p=True
for l in L:
  t+=l[0]
  if t > l[1]:
    p=False
    break
print("Yes" if p else "No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    N = int(input())
    AB = [list(map(int, input().split())) for i in range(N)]
    AB.sort(key=lambda x: x[1])
    work = 0
    ans = 'Yes'
    for i in range(N):
        work += AB[i][0]
        if work > AB[i][1]:
            ans = 'No'
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())

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

AB.sort()

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

print("Yes")

Submission status: Accepted

Solution code:
import sys
import math


N = int(input())

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

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

sum_time = 0
for i in timelis:
    need = i[0]
    deadline = i[1]

    sum_time = sum_time + need

    if sum_time > deadline:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

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

t=a[0][1]
for x in a:
    t=min(x[1],t)-x[0]
print("Yes" if t>=0 else "No")

Submission status: Accepted

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

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

ans="Yes"
sum_A=0
for i in range(N):
    sum_A+=AB[i][0]

    if sum_A>AB[i][1]:
        ans="No"
        break

print(ans)

Submission status: Accepted

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

tsk.sort(key=lambda x: x[1])
cnt = 0
A = [0]

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

Submission status: Accepted

Solution code:
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])
r = 0
flag = True
for a, b in ab:
    r += a
    if r > b:
        flag = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = "Yes"

temps = 0
for a,b in tab:
	temps+=a
	if temps>b: ans = "No"
	
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

A = []

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

def Sort(F): 
  
    # reverse = None (Sorts in Ascending order) 
    # key is set to sort using second element of  
    # sublist lambda has been used 
    F.sort(key = lambda x: x[1]) 
    return F 

A = Sort(A)

date = 0

for i in range (0, N):
	if date + A[i][0] > A[i][1]:
		print('No')
		exit()
	else:
		date+=A[i][0]

print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split()))[::-1] for _ in range(n)]
l.sort()
t=0

ans="Yes"
for m in l:
  t+=m[1]
  if t>m[0]:
    ans="No"
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])
ab = sorted(ab, key=lambda x: x[1])

memo = 0
flag = True
for a,b in ab:
    memo += a
    if b < memo:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

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])
m = 0
ans = "Yes"
for ai,bi in ab:
    m += ai
    if m > bi:
        ans = "No"
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

# @njit
def solve(n,l):
  l = sorted(l,key=lambda x: x[1])
  consumedTime = 0
  flag = True
  for i in range(n):
    if not flag:
      break
    consumedTime += l[i][0]
    if consumedTime > l[i][1]:
      flag = False
  return flag



def main():
  N = int(input())
  # N,M = map(int,input().split())
  l = [tuple(map(int,input().split())) for _ in range(N)]
  print("Yes" if solve(N,l) else "No")
  return

if __name__ == '__main__':
  main()