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 D_Megalomania():
    N = int(input())
    A = [0 for _ in range(N)]
    B = [[0,0] for _ in range(N)]
    for i in range(N):
        B[i][0] = i
        A[i], B[i][1] = map(int, input().split())

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

if __name__ == "__main__":
    D_Megalomania()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


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


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
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
'''


def MAIN():
  # T_IN()
  if A():
    print("Yes")
  else:
    print("No")


def A():
  n = IN_I()
  # [[a, b]]
  md = list([IN_L_I() for i in range(0, n)])
  md.sort(key=lambda x: (x[1]))
  total = 0
  for item in md:
    total += item[0]
    if total > item[1]:
      return False


  return True


def B():
  return None


def C():
  return None


MAIN()

Submission status: Accepted

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

def canFinishJobs(arr):
  arr.sort(key=lambda x: x[1])
  sum = 0
  for i in arr:
    sum += i[0]
    if sum > i[1]:
      return "No"
  return "Yes"

result = canFinishJobs(pairs)
print(result)

Submission status: Accepted

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

sorted_tasks = sorted(tasks, key=lambda x:x[1])
finish_time = 0
ans = "Yes"
for t in sorted_tasks:
    finish_time += t[0]
    if(finish_time > t[1]):
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

lst = [list(map(int, input().split())) for s in range(N)]
lst = sorted(lst, key=lambda x: x[1], reverse=False)

s = 0
for a, b in lst:
    s += a

    if s > b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

lst = []

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

lst = sorted(lst, key=lambda x: x[1], reverse=False)

s = 0
for a, b in lst:
    s += a

    if s > b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
lst=[]
for i in range(N):
  lst.append([int(s) for s in input().split()])
lst=sorted(lst, key=lambda x: x[1])
time=0
flag=0
for i in range(N):
  time=time+lst[i][0]
  if time>lst[i][1]:
    flag=1
    break
if flag==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n = i()
ab = mi(n)

ab.sort(key=ig(1))

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = np.array([list(map(int, input().split())) for _ in range(n)])
a_sorted = a[a[:, 1].argsort(), :]

a_sorted[:, 0] = np.cumsum(a_sorted[:, 0])
print("Yes" if all(map(lambda x: x[0] <= x[1], a_sorted)) else "No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
work_num = int(input())
work_list = []
for i in range(work_num):
    work_list.append(tuple(int(i) for i in input().split(" ")))


def ret_1th_element(tup):
    return tup[1]


work_list.sort(key=ret_1th_element)
time = 0
for i in work_list:
    time += i[0]
    if time > i[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

sorted_task = sorted(tasks, key=lambda x: x[1])  # 1番目の要素でソート
# print(sorted_task)

now = 0
for task in sorted_task:
    now += task[0]
    if now > task[1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

jobs = []
for _ in range(n):
    jobs.append([int(i) for i in raw_input().split()])

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

finish_time = 0

result = True
for job in jobs:
    finish_time = finish_time + job[0]
    if finish_time > job[1]:
        result = False
        break

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

Submission status: Accepted

Solution code:
from operator import itemgetter
a=int(input())
b=[list(map(int,input().split())) for i in range(a)]
b=sorted(b,key=itemgetter(1))
c=0
d=0
for i in range(a):
  c+=b[i][0]
  if c>b[i][1]:
    d=1
    break
    
if d==0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    items = []

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

    logging.info(items)

    items.sort()

    logging.info(items)

    total_time = 0
    for lim, val in items:
        total_time += val
        if total_time > lim:
            print("No")
            exit()

    print("Yes")

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
task = list()

for i in range(n):
    vol, limit = map(int, input().split())
    task.append((limit, vol))   # limit-first in order to sort
    
task.sort()  # sort by limit

c_time = 0
for t in task:
    c_time += t[1]
    # print(f'Job {t} finished at {c_time}')  # debug message
    if c_time > t[0]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
X = [tuple(map(int, input().split())) for _ in range(N)]
X.sort(key=lambda x:x[1])
t = 0
for a, b in X:
    t += a
    if (t > b):
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

flag = 'Yes'
passed_time = 0
for d in data:
    A, B = d
    passed_time += A
    # print(passed_time, B)
    if passed_time > B:
        flag = 'No'
        # print('BREAK')
        break

print(flag)

Submission status: Accepted

Solution code:
#4

N = int(input())
BList = []

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

sum = 0
for i in BList:
    sum += i[1]
    if (sum>i[0]):
        print("No")
        break

if(sum<=i[0]):
    print("Yes")

Submission status: Accepted

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

cur = 0
can = True
for b, a in e:
    cur += a
    if cur > b:
        can = False
        break

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

Submission status: Accepted

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

N = int(input())
x = [[0, 0] for _ in range(N)]
for i in range(N):
    x[i][1], x[i][0] = map(int, input().split())
x.sort()
t = 0
for xx in x:
    t += xx[1]
    if t > xx[0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

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

# print(data)

x = 0
flag = True
for i in range(N):
    a, b = data[i]
    x += a
    if x > b:
        flag = False

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

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])
judge = 0
flag = "Yes"
for j in range(n):
  judge += b[j][0]
  if(judge >  b[j][1]):
    print("No")
    flag = "No"
    break
    
if(flag == "Yes"):
  print("Yes")

Submission status: Accepted

Solution code:
from numpy import array, add

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

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

flg = True

a, b = array(jobs).T

s = add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import numpy as np

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

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

flg = True

a, b = np.array(jobs).T

s = np.add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
import numpy as np

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

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

flg = True

a = np.array(jobs)[:,0]
b = np.array(jobs)[:,1]

s = np.add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

time = 0
flag = 0
#print(works[1][0])

for k in range(n):
  time += works[k][0]
  if time > works[k][1]:
    flag = 1
    break
    
if flag == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

time = 0
flag = 0
#print(works[1][0])

for k in range(n):
  time += works[k][0]
  if time > works[k][1]:
    flag = 1
#  print(time)
    
if flag == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
a = [int(input()) for i in range(1)]
n = a[0]
works = [list(map(int, input().split())) for i in range(n)]
#print(works)  
works = sorted(works, key=lambda x: x[1])
work_time = 0
for w in works:
  work_time += w[0]
  if work_time > w[1]:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

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

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

flg = True
sum = 0
for a, b in jobs:
    sum += a
    if sum > b:
        flg = False
        break

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

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

work = 0
flag = 0
for i in range(n):
    work += b[i][0]
    if work > b[i][1]:
        flag = 1
        print("No")
        break

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

jobs.sort(key=itemgetter(1))

flg = True
sum = 0
for a, b in jobs:
    sum += a
    if sum > b:
        flg = False
        break

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

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

work = 0
flag = 0
for i in range(n):
    work += b[i][0]
    if work > b[i][1]:
        flag = 1
        break

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

sum_a = 0
complete = True
for i in range(N):
    sum_a += AB[i][0]
    if sum_a > AB[i][1]:
        complete = False
if complete:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import numpy as np
import sys

N = int(input())
ls = [list(map(int,input().split())) for i in range(N)]
ls = np.array(ls)
#ls = ls[ls[:,0].argsort(), :]
ls = ls[ls[:,1].argsort(), :]
# print(ls)
k=ls[0,0]
if ls[0,0]>ls[0,1]:
  print('No')
  sys.exit()
for i in range(1,N):
  k += ls[i,0]
  if k > ls[i,1]:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
import sys

N = int(input())
ls = [list(map(int,input().split())) for i in range(N)]
ls = np.array(ls)
ls = ls[ls[:,0].argsort(), :]
ls = ls[ls[:,1].argsort(), :]
# print(ls)
k=ls[0,0]
if ls[0,0]>ls[0,1]:
  print('No')
  sys.exit()
for i in range(1,N):
  k += ls[i,0]
  if k > ls[i,1]:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l_all = [list(map(int,input().split())) for i in range (N)]
l_all.sort(key = lambda x:x[1])
ryo = 0
for i in range(N):
    if l_all[i][1] < ryo + l_all[i][0]:
        print('No')
        exit()
    else:
        ryo += l_all[i][0]
print('Yes')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
from operator import itemgetter

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

N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
s = sorted(a, key=itemgetter(1))
current_t = 0

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

Submission status: Accepted

Solution code:
N = int(input())
ab = sorted([[int(x) for x in input().split()] for i in range(N)], key=lambda x:x[1])
fin = 1
if ab[0][0] > ab[0][1]:
    fin = 0
else:
    for i in range(1,N):
        ab[i][0] = ab[i-1][0] + ab[i][0]
        if ab[i][0] > ab[i][1]:
            fin = 0
            break

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

Submission status: Accepted

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

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

count = 0
limit = 0
for i in range(N):
    count += B[i][0]
    if count <= B[i][1]:
        continue
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

a=[0]*n
a[0]=x[0][0]
for i in range(1,n):
    a[i]=a[i-1]+x[i][0]

for j in range(n):
    if a[j] > x[j][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

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

print("Yes")

Submission status: Accepted

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

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

tmp = 0
flg = 0

for j in range(n):
	tmp += sort_arr[j][0]
	if tmp > sort_arr[j][1]:
		flg = 1
		break

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

Submission status: Accepted

Solution code:
import operator

N = int(input())
W = []
for i in range(N):
	Ai,Bi = map(int,input().split())
	W.append((Ai,Bi))

W.sort(key = operator.itemgetter(1,0))

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = []

    for i 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'

print(main())

Submission status: Accepted

Solution code:
# import numpy as np
import math

# S = list(input())
n = int(input())
# a, b, c, d = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(n)]

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

jobs = 0

for i in range(n):
    jobs += S[i][0]
    if jobs <= S[i][1]:
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

tmp = 0
for c, t in tasks:
    tmp += c
    if tmp > t:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  task_list = [list(map(int,input().split())) for _ in range(n)]
  task_list.sort(key = lambda x:x[1])
  curr_time = 0 
  ans = 0 # if 1, say No
  
  for k in task_list:
    curr_time += k[0]
    if curr_time > k[1]:
      ans = 1
      break

  if ans == 1:
    print("No")
  else:
    print("Yes")

main()

Submission status: Accepted

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

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 a,b in AB:
    t+=a
    if t>b:
        print("No")
        quit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N = int(input())

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

# sort
list.sort(key=lambda x:x[1])
#check
time = 0
result = True
for i in list:
    A, B = i
    time += A

    #print("work[{0}({1},{2})] time:{3}".format(i,A,B,time))

    if time > B:
        result = False
        break

message = "Yes" if result else "No"
print(message)

Submission status: Accepted

Solution code:
N = int(input())
task = []
for i in range(N):
  M = list(map(int,input().split()))
  M[0],M[1]=M[1],M[0]
  task.append(M)
task.sort()
K = 0
ans = 1
for i in range(N):
  K += task[i][1]
  if (K>task[i][0]):
    ans = 0
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N=int(input())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort(key = lambda A:A[1])
star_time = 0
ans = 'Yes'
for i in range(N):
    star_time += A[i][0]
    deadline = A[i][1]
    if deadline < star_time:
        ans = 'No'
print(ans)

Submission status: Accepted

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

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    AB = [[a,b] for a,b in zip(A, B)]
    AB = sorted(AB, key = lambda x: x[1], reverse = True)

    tail = 100000000000
    for a, b in AB:
        tail = min(tail - a, b - a)
        if tail < 0:
            print('No')
            exit()
    else:
        print('Yes')
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
N = int(input())
S = []
for i in range(0, N):
    A, B = list(map(int, input().split()))
    S.append((B, A))
S.sort(reverse=True)
T_all = 0
for i in range(0, N):
    T_all += S[i][1]
for i in range(0, N):
    if (T_all > S[i][0]):
        print("No")
        break
    else:
        T_all -= S[i][1]
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

Bs_with_index = sorted([(Bs[i], i) for i in range(len(Bs))])
indices = list(map(lambda b: b[1], Bs_with_index))

time = 0
for index in indices:
    time += As[index]
    if time > Bs[index]:
        print('No')
        break

else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

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

time_sum = 0
flag = True
for i in range(n):
    time_sum = time_sum + ab[i][0]
    if time_sum > ab[i][1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
N = int(input())
waku = []
for i in range(N):
    a,b = map(int, input().split())
    waku.append([b,a])
waku1 = sorted(waku)
ans = True
p1 = p2 = 0
for i,j in waku1:
    p1 += j
    if p1 > i:
        ans = False
        break

print("Yes" if ans 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 = sorted(list)

tpast = 0
flag = 0

for i in range(n):
    b,a = list[i][0],list[i][1]
    if tpast+a > b:
        flag = 1
        break
    else:
        tpast = tpast+a

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())

A = [[0] * 2 for i in range(N)]
for i in range(N):
  A[i] = list(map(int, input().split()))
  
A.sort(key=itemgetter(1))

now = 0
for a in A:
  now += a[0]
  if now > a[1]:
    print('No')
    exit(0)
    
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())

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

now = 0
for a in A:
  now += a[0]
  if now > a[1]:
    print('No')
    exit(0)
    
print('Yes')

Submission status: Accepted

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

for j in range(n):
    total=total+d[j][0]
    if total>d[j][1]:
        ans="No"
        

print(ans)

Submission status: Accepted

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

for j in range(n):
    total=total+d[j][0]
    if total>d[j][1]:
        ans="No"
        break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = np.zeros((N,2))

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

A = A[np.argsort(A[:,1]), :]

for i in range(N-1):
	A[i+1, 0] = A[i, 0]+A[i+1, 0]

ans = ['Yes', 'No']
t = np.sum((A[:,1]-A[:,0])<0)

print(ans[t>0])

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
c=[[0,0] for _ in range(n)]

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

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

t=0
ans='Yes'

for j in range(n):
    t=t+d[j][0]
    if t > d[j][1]:
        ans='No'
        break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ABs = [list(map(int, input().split())) for i in range(N)]
ABs.sort(key=lambda AB: AB[1])
t = 0
for i in range(N):
  AB = ABs[i]
  A = AB[0]
  B = AB[1]
  t = t + A
  if t > B:
    print("No")
    break
  if i == N-1:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
ans = "Yes"

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
N = int(input())
A=[0]*N
B=[0]*N
class Job:
    def __init__(self, a, b):
        self.time = a
        self.limit = b

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

jobs.sort(key = lambda job: job.limit)
used_time = 0
for job in jobs:
    used_time += job.time
    if used_time > job.limit:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ab = sorted([[0, 0]] + [list(map(int, input().split())) for i in range(N)], key=lambda x: x[1])
for i in range(len(ab) - 1):
    ab[i + 1][0] += ab[i][0]
    if ab[i + 1][1] < ab[i + 1][0]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ab = [[0, 0]] + [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[1])
for i in range(len(ab) - 1):
    ab[i + 1][0] += ab[i][0]
    if ab[i + 1][1] < ab[i + 1][0]:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

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


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

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()
t = 0
co = 1
for i in range(N):
    t += li[i][1]
    if li[i][0] < t:
        co = 0
        break
if co:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())

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

list.sort(key=lambda x:x[1])
  
result='Yes'
time=0
for i in range(len(list)):
  time+=list[i][0]
  if(time>list[i][1]):
    result='No'
    
print(result)