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 = []

for _ in range(N):
    job = list(map(int, input().split()))
    job.reverse()
    jobs.append(job)

jobs.sort()


sum_v = 0

for job in jobs:
    sum_v += job[1]
    if sum_v > job[0]:
        print("No")
        exit()
    
print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

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

ab = sorted(AB, key=lambda x: x[1])
task = 0
result = 'Yes'

for i in range(N):
    task += ab[i][0]
    if task > ab[i][1]:  # comparison with limit.
        result = 'No'

print(result)

Submission status: Accepted

Solution code:

N = int(input())
count = 0
D = 0
task = [list(map(int, input().split())) for _ in range(N)]
task = sorted(task, key = lambda x:x[1])
for i in range(N):
  count += task[i][0]
  if count > task[i][1]:
    print("No")
    D = 1
    break
if D== 0:
  print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

AB = []

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

X = np.cumsum(AB.T[0])
Y = AB.T[1]

Z = Y - X

ans = 'Yes'

for i in Z:
    if i < 0:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [0] * n
b = [0] * n
task = []

for i in range(n):
  a[i],b[i] = map(int, input().split())
  temp = [a[i],b[i]]
  task.append(temp)
  
task.sort(key=lambda x: x[1])
suma = 0
output = 'Yes'

for i in range(n):
  suma += task[i][0]
  if suma > task[i][1]:
    output = 'No'
    break

print(output)

Submission status: Accepted

Solution code:
n = int(input())

a = []
b = []

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

order = sorted(range(len(b)), key=lambda k: b[k])

available = False


margin = [0 for i in range(n)]
now_time = 0
for i in range(n):
    j = order[i]
    margin[j] = b[j] - (now_time + a[j])
    now_time += a[j]

if min(margin) >= 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
time = []
for i in range(n):
    a1, b1 = [int(i) for i in input().split()]
    time.append({"need": a1, "timeup":b1})
time_sorted = sorted(time, key=lambda x:x["timeup"])
t = 0
cnt = 0
for line in time_sorted:
    t += line["need"]
    if t > line["timeup"]:
        print("No")
        break
    if cnt==len(time)-1:
        print("Yes")
    cnt += 1

Submission status: Accepted

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

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

def detect(alist):
  time = 0
  for item in alist:
      time += item[0]
      if time > item[1]:
        return "No"
  return "Yes"

print(detect(new_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = []
x = 0
y = 0
sum = 0

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


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


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

print('Yes')

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    tasks = [tuple(map(int, input().split())) for _ in range(N)]
    tasks.sort(key=lambda x: x[1])
    time = 0
    for A, B in tasks:
        time += A
        if B < time:
            return 'No'
    return 'Yes'

print(main())

Submission status: Accepted

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

now = 0
for ab in AB:
    if ab[1] < now + ab[0]:
        print("No")
        exit()
    now += ab[0]

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
flag1 = 0
n = int(input())
ans_list = []
for i in range(n):
    a = list(map(int, input().split()))
    ans_list.append(a)
ans_list.sort(key=itemgetter(1))
timequeue = 0
for i in range(n):
    timequeue += ans_list[i][0]
    if timequeue > ans_list[i][1]:
        flag1 += 1
        break
if flag1 == 1:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
t = 0
ahaha = {}
for i in range(int(input())):
    tmp = input().split(" ")
    if int(tmp[1]) in ahaha:
        ahaha[int(tmp[1])].append(int(tmp[0]))
    else:
        ahaha[int(tmp[1])] = [int(tmp[0])]
for i in sorted(list(ahaha.keys())):
    for j in ahaha[i]:
        t += j
        if t > i:
            print("No")
            exit()
print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
AB = [[int(x) for x in input().split()]for _ in range(N)]
sum_time = sum([a for a,b in AB])
AB.sort(key=itemgetter(0))
AB.sort(key=itemgetter(1),reverse=True)
for a,b in AB:
    if(sum_time>b):
        print('No')
        break
    else:
        sum_time-=a
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import numpy as np


def resolve():
    N = int(input())
    L = [list(map(int, input().split())) for i in range(N)]
    L.sort(key=lambda v: v[1])
    A_sum = 0
    for a, b in L:
        A_sum += a
        if (b < A_sum):
            print("No")
            return
    print("Yes")
resolve()

Submission status: Accepted

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

    total = 0
    for job in jobs:
        total += job[0]
        if total > job[1]:
            ans = "No"
            break
    else:
        ans = "Yes"
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
    
N  = int(input())
    
AB = []
time = 0
    
for _ in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
    
sorted_AB = AB[AB[:,1].argsort(), :]
    
for i in range(N):
    time += sorted_AB[i,0]
    
    if time > sorted_AB[i,1]:
        print('No')
        exit()
    
print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
import sys
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
arr = sorted(a, key = lambda x:x[1])
#print(arr)
#arr = np.array(a)
#arr_sort = np.sort(arr, axis=0)
#print(arr_sort)

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

print('Yes')

Submission status: Accepted

Solution code:
print('YNeos'[any(time>b for time,N in ((0,int(input())),) for tasks in ([tuple(map(int, input().split())) for _ in range(N)],) if not tasks.sort(key = lambda i: i[1]) for a, b in tasks for time in (time+a,))::2])

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[i]はA[i]まで終わらせるためにかかる累積時間
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 = []
s = 0
for i in range(n):
  a, b = map(int, input().split())
  s += a
  l.append((a, b))
  
l = sorted(l, key=lambda x: x[1])
for i in range(n):
  if s > l[-1][1]:
    print("No")
    exit()
  else:
    a = l.pop()[0]
    s -= a
print("Yes")

Submission status: Accepted

Solution code:
import sys

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

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

now = 0
for time, dead in tasks:
    now += time
    if now > dead:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
 
BA = []
 
for _ in range(N):
    a, b = list(map(int, input().split()))
    BA.append([b, a])
 
BA.sort()
 
a = 0
 
flg = False
for ba in BA:
    b = ba[0]
    a += ba[1]
    if b < a:
        flg = True
        break
 
if flg:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys

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

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


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

time = 0

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

Submission status: Accepted

Solution code:
import numpy as np

N  = int(input())

AB = []
time = 0

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

AB = np.array(AB)

sorted_AB = AB[AB[:,1].argsort(), :]

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

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

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = []
for x in range(n):
  b = [int(xx) for xx in input().split()]
  a.append(b)
a.sort(key = lambda x : x[1])
#print(a)

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

Submission status: Accepted

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

flag = 0
sums = 0
for i in range(N):
    sums += task[i][0]
    if(sums > task[i][1]):
        flag = 1
        
if flag:
    print("No")
else:
    print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
A, B = [], []
for _ in range(N):                                                                                                                                                                                          
    a, b = (int(x) for x in input().split())                                                                                                                                                                
    A.append(a)                                                                                                                                                                                             
    B.append(b)                                                                                                                                                                                             

B_ = sorted(B)
B_id = sorted(range(len(B)), key=lambda k:B[k])

time = 0
for i in range(N):                                                                                                                                                                                          
    time += A[B_id[i]]                                                                                                                                                                                      
    if time > B_[i]:                                                                                                                                                                                        
        print('No')                                                                                                                                                                                         
        sys.exit()                                                                                                                                                                                          

print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n=int(input())
a=[]
for _ in range(n):
	x,y=map(int,input().split( ))
	a.append((x,y))
a.sort(key=itemgetter(1))
total=0
for b,c in a:
	total+=b
	if total>c:
		print("No")
		exit(0)
	
print("Yes")

Submission status: Accepted

Solution code:
import sys

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

for i in range(N):
  s = input().split()
  mylist += [[int(s[0]),int(s[1])]]

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

mysum = 0
for i in mylsit:
  mysum += i[0]
  if mysum <= i[1]:
    continue
  else:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
lis = []
for _ in range(N):
  X = list(map(int,input().split()))
  X.reverse()
  lis.append(X)
lis.sort()
t = 0
for i in range(N):
  t += lis[i][1]
  if t > lis[i][0]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N=input()
A=[];B=[]
P=[]
for i in range(N):
    a,b=map(int,raw_input().split())
    A.append(a);B.append(b)
    P.append((b,a))
P.sort()

t=0
for b,a in P:
    t+=a
    if t>b:
        print("No")
        sys.exit(0)
print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
T=[]
append=T.append
for i in range(n):
  a,b=map(int,input().split())
  append([a,b])
T.sort(key=lambda x:x[1])
chk=True
t=0
for i in range(n):
  a,b=T[i]
  t+=a
  if t>b:
    chk=False
print("Yes" if chk==True else "No")

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for i in range(N):
    b, a = map(int, input().split())
    if a in dic.keys():
        dic[a] += b
    else:
        dic[a] = b
t = 0
for i, j in sorted(dic.items()):
    t += j
    if i < j or t > i:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n=int(input())
list_a = []
list_b = []
for i in range(n):
    a,b=map(int,input().split())
    list_a.append(a)
    list_b.append(b)
"""n=5
list_a = [2,1,1,4,3]
list_b = [4,9,8,9,12]"""


list_dd =[]
for d in zip(list_b, list_a):

    #print(d)
    list_dd.append(list(d))
    
#print(list_dd)

list_dd=sorted(list_dd)
ss=0
for i in range(n):
    tmp=list_dd[i][1]
    ss+=tmp
    list_dd[i][1]=ss

#print(list_dd)

for i in range(n):
    if list_dd[i][0]<list_dd[i][1]:
        
        print("No")
        break
    elif i == n-1:
        print("Yes")

Submission status: Accepted

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

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

total = 0
able = True
for i in hoge:
    total += i[0]
    if i[1]<total:
        able = False

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = []
    for _ in range(N):
        temp = list(map(int, input().split()))
        AB.append((temp[0], temp[1]))

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

    total_time = 0
    flag = True
    for x in sorted_AB:
        total_time += x[0]
        if total_time > x[1]:
            flag = False
            break

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

n = int(input())
lines = sys.stdin.readlines()

works = [None]*n
_ = 0
for l in lines:
    works[_] = tuple(map(int, l.split(" ")))
    _ += 1

works.sort(key=lambda w:w[1], reverse=True)


time = 9999999999999999999999999
for i,w in enumerate(works):
    time = min(time,w[1]) - w[0]

print("Yes" if time >= 0 else "No")

Submission status: Accepted

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

data.sort(key = lambda x: x[1])
temp = True
now = 0
for i in range(n):
    if now + data[i][0] > data[i][1]:
        temp = False
        break
    else:
        now += data[i][0]
if temp:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

nowtime=0
for time,limit in task:
    nowtime+=time
    if nowtime>limit:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = sorted(
        [tuple(map(int, input().rstrip().split())) for _ in range(n)], key=lambda x: x[1]
    )
    tasks = 0
    for i, j in arr:
        tasks += i
        if tasks > j:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
def main():
    n = int(input())
    arr = sorted(
        [tuple(map(int, input().rstrip().split())) for _ in range(n)], key=lambda x: x[1]
    )
    tasks = 0
    for i, j in arr:
        tasks += i
        if tasks > j:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
Y = [[int(i) for i in input().split()] for i in range(n)] 
X = sorted(Y, key=lambda x:x[1])
A = [a[0] for a in X]
B = [b[1] for b in X]
A.append(0)
sum_A = A[0]
evaluate = 0
for j in range(n):
    if sum_A <= B[j]:
        sum_A = sum_A + A[j+1]
        evaluate += 1
if evaluate == n:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

str='Yes'
total=0
time=0
for i in range(N):
    a,b, = map(int, input().split())
    A.append([b,a])

A.sort()


for j in range(N):
    if time<=A[j][0]:
        time = A[j][0]

    A[j][0]=100000000000
    total +=A[j][1]

    if total>time:
        str='No'
print(str)

Submission status: Accepted

Solution code:
import scipy as sp
N = int(input())
l = []
for i in range(N):
    l.append(list(map(int, input().split())))

l = sp.array(sorted(l, key=lambda x: x[1]))

a = sp.cumsum(l[:,0])
b = l[:,1]

c = b-a
t = True
for i in c:
    if i < 0:
        t = False
        print("No")
        break

if t:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

a_b_lis = [0] * N

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

count = 0
#print(a_b_lis)
a_b_lis = sorted(a_b_lis, key=lambda x: x[1])

on_time = True
for item in a_b_lis:
    count += item[0]
    if count > item[1]:
        on_time = False
if on_time:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
N=int(input())

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

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

impos = False

calc = []
calc.append(pair[0][0])
for i in range(N-1):
    calc.append(calc[i]+pair[i+1][0])

for i in range(N):
    if calc[i]>pair[i][1]:
        impos = True

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

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())

ablist = [list(map(int, input().split())) for _ in range(n)]
ablist = sorted(ablist, key=itemgetter(1))

wa = 0
for i in ablist :
    wa += i[0]
    if wa > i[1] :
        print("No")
        break
else :
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array([list(map(int, input().split())) for i in range(n)])
a = a[np.argsort(a[:, 1])]
ans = "Yes"
k = 0
for i in range(len(a)):
    k += a[i,0]
    if k > a[i,1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
a = [0] * N
b = [0] * N
c = [0] *N


for i in range(N):
    a[i],b[i] = map(int,input().split())
    c[i] = [b[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    sums+=c[i][1]
    if c[i][0] < sums:
        correct=0
        break
        
if correct:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
import collections

N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in sorted(dic.items(),key=lambda x:x[0]):
    if v+prev_time > k:
        result = "No"
        break
    prev_time += v

print(result)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

ans = 'Yes'
bef_b = 0
time = 0
for a,b in ab:
	if b-bef_b+time-a < 0:
		ans = 'No'
		break
	time += b-bef_b-a
	bef_b = b

print(ans)

Submission status: Accepted

Solution code:
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    task = [tuple(map(int, input().split())) for _ in range(n)]
    tmp = 0
    task.sort(key=lambda x:x[1])
    for a, b in task:
        tmp += a
        if tmp > b:
            print("No")
            return
    print("Yes")

main()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
def input():
    return sys.stdin.readline()[:-1]
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a.sort(key=itemgetter(1))
ans = "Yes"
k = 0
for i in range(len(a)):
    k += a[i][0]
    if k > a[i][1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

sortAB = sorted(AB, key = lambda x: (x[1]))
t = 0
for a, b in sortAB:
  t += a
  if t > b:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:


N = int(input())
jobs = [0] * N
for i in range(N):
    Ai,Bi = list(map(int,input().split()))
    jobs[i] = (Bi,Ai)
jobs = sorted(jobs)
flag = True
sumT = 0
for bi,ai in jobs:
    sumT += ai
    if bi < sumT:
        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)]

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 = int(input())
AB = [tuple([int(_) for _ in input().split()]) for i in range(N)]

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

result = True

t = 0
for a, b in AB:
    if t + a > b:
        result = False
        break
    else:
        t += a

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from operator import itemgetter
N = int(input())
job = [list(map(int, input().split())) for _ in range(N)]
#print(job)
job.sort(key=itemgetter(1))
#print(job)
now = 0
t = 0
for j in job:
    now += j[0]
    if now > j[1]:
        print("No")
        t = 1
        break
if t == 0:
    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])

cost = 0
limit = 0

for i in range(n):
    cost += ab[i][0]
    limit = ab[i][1]
    if limit < cost:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
X = [list(map(int, input().split())) for n in range(N)]
X = sorted(X, key=lambda x: x[0])
X = sorted(X, key=lambda x: x[1])
cnt = 0
isLimitOver = False
for x in X:
    cnt += x[0]
    if cnt > x[1]:
        isLimitOver = True
        break
if isLimitOver:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
  
listB = sorted(listA)
listC = sorted(listB, key=itemgetter(1))

flag = 0
time = 0
for i in range(N):
	time += listC[i][0]
	if time > listC[i][1]:
		flag = 1
		break
 
if flag==0:
	print('Yes')
elif flag==1:
	print('No')

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    
    AB = []
    for i in range(N):
        AB.append([int(x) for x in stdin.readline().rstrip().split()])
    AB.sort(key=lambda x:x[1])
    
    ans = "Yes"
    sum = 0
    for ab in AB:
        sum += ab[0]
        if sum > ab[1]:
            ans = "No"
            break
    print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
  
listB = sorted(listA)
la = sorted(listB, key=itemgetter(1))
 
t = 0
for i in range(N):
	t += la[i][0]
	#print(t)
	if t > la[i][1]:
		print('No')
		sys.exit()
 
print('Yes')

Submission status: Accepted

Solution code:
import sys, itertools, collections, fractions
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n = int(input())
a = [lmi() for i in range(n)]
c = 0
# print(sorted(a, key = lambda x: x[1]))
for i in sorted(a, key = lambda x: x[1]):
    c += i[0]
    # print(c)
    if c > i[1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

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

output = 'Yes'
time = 0
for ab in AB_list_sorted:
    time += ab[0]
    if ab[1] < time:
        output = 'No'
        break

print(output)

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split())
c=f=0
for b,a in sorted(zip(t[1::2],t[::2])):c+=a;f|=c>b
print('YNeos'[f::2])

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

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

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    l.sort(key=itemgetter(1))

    is_possible = True
    sum = 0
    for e in l:
        sum += e[0]
        if sum > e[1]:
            is_possible = False
            break

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

Submission status: Accepted

Solution code:
import numpy as np
import sys

if __name__ == '__main__':
    n = int(input())
    works = np.array([[int(i) for i in input().split()] for i in range(n)])
    col_num = 1
    sorted_works = works[np.argsort(works[:, col_num])]
    time = 0
    for i in range(n):
        time += sorted_works[i][0]
        if time > sorted_works[i][1]:
            print("No")
            sys.exit()

        else:
            None

    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
 
#print(listA)
 
listB = sorted(listA)
la = sorted(listB, key=itemgetter(1))
 
t = 0
for i in range(N):
	s = la[i][1]
	t += la[i][0]
	if t > s:
		print("No")
		sys.exit()
 
print('Yes')