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

ABs = []

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

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

times = 0
before_line = 0
for ab in sorted_ABs:
    times += (ab[1] - before_line)
    before_line = ab[1]
    tmp = times - ab[0]
    if tmp < 0:
        print("No")
        exit()

    times -= ab[0]

print("Yes")

Submission status: Accepted

Solution code:


n = int(input())

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


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


#print(abn)

ts = 0 # time_stamp
enable = True
for abi in abn:
    a, b = abi

    if not ts + a <= b:
        enable = False
        break
    else:
        ts += a

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

Submission status: Accepted

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

Submission status: Accepted

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

time = 0

for A, B in work:
    time += A
    if time > B:
        print("No")
        break
        
else:
    print("Yes")

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

l = []

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

l = np.array(l)
l = l[np.argsort(l[:,1],axis=0)]
ans = l[:,1]-np.cumsum(l[:,0])
ans = np.where(ans<0)[0]

print("Yes" if ans.shape[0]==0 else "No")

Submission status: Accepted

Solution code:
import sys

N = int(input())

jobs = []

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

jobs = sorted(jobs)

time = 0

for job in jobs:
    time += job[1]
    if time > job[0]:
        print('No')
        sys.exit(0)

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
tasks = []
for i in range(0, N):
  t = list(map(int, input().split(' ')))
  tasks.append(t)
tasks = sorted(tasks, key=lambda x: x[1])
sum_time = 0
is_done = True
for t in tasks:
  sum_time += t[0]
  if sum_time > t[1]:
    is_done = False
    break
if is_done:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
# 最初に入れておくとinputが早くなる
from operator import itemgetter
import sys
input = sys.stdin.readline

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

sate = [0]
flag = True

for i in range(n):
    sate.append(sate[i] + l[i][0])
    if (sate[i + 1] > l[i][1]):
        flag = False
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([b, a])   # b順にsortするので
AB.sort()

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a,b = [],[]
ideal = 0
real = 0
for i in range(n):
    a1,b1 = map(int, input().split())
    a.append(a1)
    b.append([b1,i])

b.sort()
for i in range(n):
    ideal = max(ideal, b[i][0])
    real += a[b[i][1]]
    if real > ideal:
        print("No")
        break
    if i == n-1:
        print("Yes")

Submission status: Accepted

Solution code:
# coding:utf-8

import math

def main():
    n = int(raw_input())
    cnt = n # TODO: edit here
    ps = []
    for i in range(cnt):
        a,b = map(int, raw_input().split())
        ps.append([b,a])
    ps.sort()
    total = None
    chk = True
    now = 0
    for i in ps:
        tmp = i[0] - i[1]
        if total == None:
            if tmp >= 0:
                total = tmp
                now = i[0]
            else:
                chk = False
                print "No"
                break
        else:
            total = total + i[0] - now - i[1]
            now = i[0]
            if total < 0:
                chk = False
                print "No"
                break
    if chk:
        print "Yes"

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A_B = []
for i in range(N):
	A_B.append(list(map(int,input().split())))
A_B = np.array(A_B)

A_B_sort = A_B[np.argsort(A_B[:,1])]
time = 0
judge = True
for A_B_data in A_B_sort:
	time += A_B_data[0]
	if time > A_B_data[1]:
		judge = False
		break
if judge:
	print("Yes")
else:
	print("No")

Submission status: Accepted

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

from operator import itemgetter

n = int(input())
work = []
for i in range(n):
	a, b = map(int, input().split())
	c = b-a
	work.append([a, b, c]) # [かかる時間, 終わらせる時間, 始めないといけない時間]
work.sort(key = itemgetter(1))
# print(work)

time = 0
for item in work:
	# print(item, time)
	if time <= item[2]:
		time += item[0]
	else:
		print("No")
		exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = {}
for i in range(N):
  A,B = map(int,input().split())
  if B in AB.keys():
    AB[B] += A
  else:
    AB[B] = A
time = 0
for b in sorted(AB.keys()):
  time += AB[b]
  if time > b:
    print("No")
    break
else:
  print("Yes")

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A = []
B = []

for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
A = np.array(A)
B = np.array(B)

J = np.argsort(np.array(B))
A = A[J]
B = B[J]

A = np.cumsum(A)

ans = np.min(B - A)

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

Submission status: Accepted

Solution code:
import sys

N = int(input())
a = [[int(i) for i in input().split()] for i in range(N)]

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

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

Submission status: Accepted

Solution code:
n = int(input())

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

ab.sort(key=lambda x: x[1])
time = 0
for i in range(n):
    time += ab[i][0]
    if time > ab[i][1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

N = int(input())

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

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

AB[0][2] = AB[0][0]
for i in range(N - 1):
    AB[i + 1][2] = AB[i][2] + AB[i + 1][0]

for i in range(N):
    if AB[i][1] < AB[i][2]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:

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

ab.sort()
s = 0
flg = 0
##print(ab)
for i in range(n):
    s += ab[i][1]
    if s>ab[i][0]:
        flg = 1
        break

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

else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# N = 2 * 10^5
N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

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

sum_time = 0

for A, B in AB:
    sum_time += A

    if sum_time > B:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
import sys

def main():
    n = int(sys.stdin.readline().strip())
    task = [tuple(int(i) for i in sys.stdin.readline().strip().split()) for _ in range(n)]
    task.sort(key=lambda x: x[1])
    time = 0
    for t in task:
        time += t[0]
        if time > t[1]:
            return 'No'
    return 'Yes'

print(main())

Submission status: Accepted

Solution code:
def main():
     n=int(input())
     task=[list(map(int,input().split())) for i in range(n)]
     task.sort(key=lambda x:x[1])
     now=0
     flag=0
     for task_i in task:
          now+=task_i[0]
          if now>task_i[1]:
               print("No")
               flag=1
               break
     if flag==0:
          print("Yes")
          
     
if __name__=='__main__':
     main()

Submission status: Accepted

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

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

time = 0
answer = "Yes"
for i in range(N):
    A, B = ABs[i]
    time += A
    if time > B:
        answer = "No"
        break

print(answer)

Submission status: Accepted

Solution code:
#[N,K] = list(map(int,input().split()))
#A = list(map(int,input().split()))
#[A,B,C,D] = list(map(int,input().split()))
N = int(input())
AB = [list(map(int,input().split())) for i in range(N)]
#N = 3
#AB = [[334, 1000], [334, 1000], [334, 1000]]
AB.sort(key = lambda x:x[1])
sum_tmp = 0
idx = 0
for i in range(len(AB)):
    sum_tmp += AB[i][0]
    if sum_tmp > AB[i][1]:
        idx = 1
if idx == 0:
    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])
t=0
for a,b in ab:
    t+=a
    if t>b:
        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])

tmp = 0
flag = True
for i in range(N):
    tmp += ab[i][0]
    if tmp > ab[i][1]:
        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])

flag = True
t = 0
for i in range(len(ab)):
    a, b = ab[i]
    t += a
    if b < t:
        flag = False
        break


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

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

result = 'Yes'
a_sum, b_sum = 0, 0

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

Submission status: Accepted

Solution code:
n = int(input())
ab_s = [[int(v) for v in input().split()] for _ in range(n)]

ab_s.sort(key=lambda x:x[1])
c = 0
for i in range(n):
  c += ab_s[i][0]
  if c > ab_s[i][1]:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
dic = [[0,0] for i in range(N)]
for i in range(N):
    A = input().split(" ")
    dic[i] = A

dic_s = sorted(dic,key=lambda x: int(x[1]))

t = 0
ans = "Yes"
for i in range(N):
    
    t += int(dic_s[i][0])
    if (t > int(dic_s[i][1])):
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
work=[[0,0]for i in range(N)]
sum=0
ans=0
for x in range(N):
  inp=input().split()
  work[x][0]=int(inp[1])
  work[x][1]=int(inp[0])
work2=sorted(work)
for y in range(N):
  sum+=work2[y][1]
  if sum>work2[y][0]:
    ans=1
    break
if(ans==0):
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
N=int(input())
AB = [[int(i) for i in input().split()] for j in range(N)]
ABDeadStart = [[A,B,B-A] for A,B in AB]#所要時間、初めてないと駄目な時間
MaxShoyou = sum([a for a,b,kaisi in ABDeadStart])
ABDeadStart.sort(key = lambda x:x[2]-MaxShoyou+x[0])
curtime = 0
NO =0
for a,b,ds in ABDeadStart:
    if curtime <= ds:
        curtime += a
    else:
        NO =True
        break
if NO :print("No")
else:print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
ab = sorted([list(map(int, input().split())) for i in range(n)], key=itemgetter(1))
t = 0
for i in ab:
    a, b = i
    t += a
    if b < t:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
AB =np.zeros((N,2),dtype=np.int32)
for i in range(N):
    AB[i,:]=list(map(int,input().split()))

ABs = AB[np.argsort(AB[:, 1])]

output = "Yes"

T = 0
for i in range(N):
    T += ABs[i,0]
    if T>ABs[i,1]:
        output = "No"

print(output)

Submission status: Accepted

Solution code:
from sys import stdin
import math


n = int(stdin.readline().rstrip())

m = {}

for i in range(n):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if b in m:
      m[b] += a
    else:
      m[b] = a

mm = sorted(m.items(), key=lambda x:x[0])
#print(mm)
ans = "Yes"
sum = 0
for k,v in mm:
  #print(k,v)
  sum += v
  if sum > k:
      ans = "No"
      break

print(ans)

Submission status: Accepted

Solution code:
N = int(input().strip())

AB = [[int(i) for i in input().strip().split()] for _ in range(N)]
AB = sorted(AB, key=lambda a: a[1])

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

Submission status: Accepted

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

sb = sorted(range(len(listb)), key=lambda k: listb[k])

listb.sort()
lista = []
for i in range(n):
    ii = sb[i]
    lista.append(listat[ii])

#print(lista)
#print(listb)
time = 0
ans = "Yes"
for i in range(n):
    time+=lista[i]
    if time>listb[i]:
        ans = "No"
        break 
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ls = [[int(x) for x in input().split()] for _ in range(n)]

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

now=0

for i in range(n):
    now+=ls[i][0]
    if now<=ls[i][1]:
        pass
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
ABs = [list(map(int, input().split())) for i in range(N)]
ABs = sorted(ABs, key=lambda x:x[1])
total = 0
is_comp = True
for task_i in ABs:
    total += task_i[0]
    #print("total: {}, limit: {}".format(total, task_i[1]))
    if total > task_i[1]:
        is_comp = False
        break
if is_comp:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N = int(input())
X = [None]*N
for k in range(N):
	X[k] = tuple(map(int,input().split()))
X.sort(key=lambda q: q[1])
time = 0
late = 0
for x in X:
	time += x[0]
	if time > x[1]:
		late = 1
		break
if late == 1:
	print("No")
else:
	print("Yes")

Submission status: Accepted

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

s = 0
for ab in AB:
    s += ab[0]
    if s > ab[1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

AB.sort(key=lambda x: x[1])
# print(N, AB)

c = 0
p = True
for ab in AB:
    c += ab[0]
    if c > ab[1]:
        p = False
        break

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

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    time = 0
    due = 0

    for i in range(n):
        time += task[i][0]
        due = max(due,task[i][1])
        if time > due:
            print('No')
            exit()
    
    print('Yes')
    return 0

solve()

Submission status: Accepted

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

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

memo = memo[np.argsort(memo[:,1])]
#print(memo)
flag = True
s = 0
for i in range(N):
    s += memo[i,0]
    if memo[i,1]-s<0:
        flag = False
        break

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

Submission status: Accepted

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

deth =0
time =0
ans = 0
for i in l:
    deth = i[1]
    time += i[0]
    if deth < time:
        print("No")
        ans += 1
        break
if ans == 0:
    print("Yes")

Submission status: Accepted

Solution code:
from functools import reduce
from operator import add

N = int(input())
AB = []
for i in range(N):
    AB.append(tuple([int(x) for x in input().split(' ')]))

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

total = 0
f = True
for a, b in AB:
    total += a
    if total > b:
        f = False
        break

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N = int(input())

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

BA.sort()

c = 0
ans = True
for i in range(N):
    b, a = BA[i]
    c += a
    # print("i:{}, c:{}, a:{},b:{}".format(i, c, a, b))
    if c > b:
        ans = False
        break

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

Submission status: Accepted

Solution code:
# D問題
N = int(input())
ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))
ab = sorted(ab, key = lambda x:x[1])
time = 0
flag = True
for i in range(N):
    time += ab[i][0]
    if time > ab[i][1]:
        flag = False
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[1])
time = 0
for i in range(N):
    time += L[i][0]
    if time > L[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    tasks = [tuple(map(int, input().split())) for _ in range(N)]
    tasks = sorted(tasks, key=lambda x: x[1])
    ct = 0
    for t in tasks:
        if ct+t[0] > t[1]:
            return False
        ct += t[0]
    return True

if __name__ == '__main__':
    if main():
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def LI(): return list(map(int, input().split()))

n = int(input())
pair = []
for _ in range(n):
    _a, _b = LI()
    pair.append((_b, _a))

pair.sort()

acc = 0
last_b = 0
for b, a in pair:
    acc += (b - last_b) - a
    last_b = b

    if acc < 0:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

def solve():
    N = int(input())
    hq = []
    for i in range(N):
        A, B = map(int, input().split())
        heappush(hq, (B,A))

    time = 0
    cost = 0
    while hq:
        l, c = heappop(hq)
        if time == l:
            cost += c
        else:
            time = l
            cost += c
        if cost > time:
            return 'No'
    return 'Yes'
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
from operator import itemgetter

def main():
    n = int(input())
    works =[]
    for i in range(n):
        works.append(tuple(map(int,input().split(" "))))
    sortworks = sorted(works, key=itemgetter(1))
    
    time = 0
    flag = True
    for i in sortworks:
        time += i[0]
        if time > i[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

class Work:
    weight = 0
    deadline = 0
    
    def __init__(self, w, d):
        self.weight = w
        self.deadline = d
        
    def __lt__(self, other):
        return self.deadline < other.deadline
        
N = int(input())
works = []
for l in range(N):
    a,b = [int(i) for i in input().split()]
    works.append(Work(a,b))
    
works.sort()
keika = 0
ans = "Yes"
for i in range(len(works)):
    keika += works[i].weight
    if keika > works[i].deadline:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8


def main():
    N = int(input())
    # N, M = map(int, input().split())
    task = []
    for i in range(N):
        Ai, Bi = map(int, input().split())
        task.append([Ai, Bi])
    time = 0
    task.sort(key=lambda x: x[1])
    # print(task)
    ans = True

    for i in range(N):
        Ai, Bi = task[i]
        time += Ai
        if time > Bi:
            ans = False
            break

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n):
    l += [list(map(int,input().split()))]
l = sorted(l,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())
works = []
for _ in range(n):
    a,b = map(int,input().split())
    works.append([a,b])
works = sorted(works,key=lambda x:x[1])
time = 0
flag = 0
for work in works:
    a,b = work
    time += a
    if time > b:
        flag = 1
        break

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

Submission status: Accepted

Solution code:
N = int(input())
l = [None]*N
for i in range(N):
    l[i] = [int(x) for x in input().split()]
new_list = sorted(l, key = lambda z:z[1])
total_time = 0
for i in range(N):
    total_time += new_list[i][0]
    if total_time > new_list[i][1]:
        print('No')
        exit()
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys

N = int(input())
worktime, deadline = [], []

for _ in range(N):
    a, b = map(int, input().split())
    worktime.append(a)
    deadline.append(b)

union = sorted(zip(worktime, deadline), key=lambda x: x[1])
worktime, deadline = zip(*union)

current = 0
for i in range(N):
    if current + worktime[i] > deadline[i]:
        print("No")
        sys.exit()
    else:
        current += worktime[i]
        pass
print("Yes")

Submission status: Accepted

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

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

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

t = 0
for t_job, t_dead in AB:
    t += t_job
    if (t_dead < t):
        print('No')
        sys.exit()

print('Yes')

Submission status: Accepted

Solution code:

N = int(input())

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

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

now = 0
remain = 0

for job in sorted_jobs:
    cost = job[0]
    limit = job[1]

    remain += limit - now
    now = limit

    remain -= job[0]

    if remain < 0:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
BA = [[int(n) for n in input().split()][::-1] for _ in range(N)] # deadline, time
BA = sorted(BA)
T = 0
for ba in BA:
    T += ba[1]
    if T > ba[0]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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


n = int(input())
q = []

for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(q, (b, a))

wk_time = 0
finished = True
for _ in range(n):
    b, a = heapq.heappop(q)
    wk_time += a
    if wk_time > b:
        finished = False
        break

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

Submission status: Accepted

Solution code:
# coding: utf-8
from sys import stdin
import sys, fractions
import numpy as np

def main():
    n = int(stdin.readline().rstrip())
    matrix = [stdin.readline().rstrip().split() for _ in range(n)]
    matrix = np.array(matrix, dtype='int32')
    matrix = matrix[np.argsort(matrix[:,-1])]
    task_time = matrix[:,0]
    task_time_sum = np.cumsum(task_time)
    limited_time = matrix[:,-1]
    #print(n, matrix)
    #print(task_time, task_time_sum)
    for x, y in zip(task_time_sum, limited_time):
        if x > y:
            return(0)
    
    return(1)
    
if __name__ == '__main__':
    ans = main()
    print('Yes' if ans==1 else 'No')

Submission status: Accepted

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

for i in range(N):
	a, b = (map(int, input().split()))
	A.append([a, b])
	
A = sorted(A, key = lambda x : x[1])
summ = 0
output = 'Yes'

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys

N = int(input())

X = []
for _ in range(N):
    X.append(list(map(int, input().rstrip().split(' '))))
    
X = sorted(X, key=lambda x: x[1])

cumsum = 0
for i in range(N):
    cumsum += X[i][0]
    if X[i][1] < cumsum:
        print('No')
        sys.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])
t=0
for a,b in ab:
    t+=a
    if t>b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left


class Solution:
    def main(self):
        N = int(input())
        AB = []
        for i in range(N):
            a, b = map(int, input().split())
            AB.append((a, b))
        AB = sorted(AB, key=lambda x: x[1])

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


if __name__ == '__main__':
    Solution().main()

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())
  
  
index = np.argsort(B)
Asort = [0]*N
Bsort = [0]*N
for i in range(N):
  Bsort[i] = B[index[i]]
  Asort[i] = A[index[i]]
  
flag = True
val = 0
for i in range(N):
  val = val+Asort[i]
  if val > Bsort[i]:
    flag = False
if flag==True:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
from operator import itemgetter, attrgetter

N = int(input())

pairs = []

for n in range(N):
  pairs.append(tuple(map(int, input().split())))

pairs = sorted(pairs, key=itemgetter(1))
  
t = 0

for p in pairs:
  t += p[0]
  if p[1] < t:
    print('No')
    exit(0)
    
print('Yes')

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    N = int_raw()
    BAs = []
    for i in range(N):
        A,B = ints_raw()
        BAs.append([B,A])
    BAs.sort()
    t = 0
    for BA in BAs:
        B,A = BA
        t+=A
        if B<t:
            return "No"
    return "Yes"


print(main())

Submission status: Accepted

Solution code:
def solve():
    BA = sorted(list(map(int, input().split()))[::-1] for _ in range(int(input())))
    cnt = 0
    for b, a in BA:
        if cnt + a <= b:
            cnt += a
        else:
            return "No"
    return "Yes"
print(solve())

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]:
        ans = 'No'
        break

print(ans)

Submission status: Accepted

Solution code:
N = input()

arr = []

for i in xrange(N):
    a,b = map(int,raw_input().split())
    arr.append([a,b])

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

time = 0
ans = 'Yes'


for i in xrange(N):
    time += arr[i][0]
    if arr[i][1]-time < 0:
        ans = 'No'
        break
    arr[i].append(time)

# print ''
# for i in xrange(N):
#     print arr[i]

print ans

Submission status: Accepted

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

for _ in range(n):
    a, b = [int(i) for i in input().split()]
    l.append({'cost': a, 'deadline': b})

def solve(list):
    list_sorted = sorted(list, key=lambda x:x['deadline'])

    t = 0
    for i in list_sorted:
        t = t + i['cost']
        if t > i['deadline']:
            return False

    return True


print('Yes' if solve(l) else 'No')