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())
AB = [list(map(int, input().split())) for _ in range(N)]
#Aはかかる時間、Bは締め切り時間
AB = sorted(AB,key=lambda x: x[1])

C = [0]*len(AB)
C[0] = AB[0][0]
for i in range(1,len(AB)):
    C[i] += AB[i][0] + C[i-1]

ans = 1
for i in range(len(AB)):
    if AB[i][1] < C[i]:
        ans = 0

print('YNeos'[ans==0::2])

Submission status: Accepted

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

Submission status: Accepted

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

def solve():
  current_time = 0
  for work in sorted(AB, key=lambda x: x[1]):
    current_time += work[0]
    if current_time <= work[1]:
      pass
    else:
      return False
  return True

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

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
jobs = [tuple(map(int, sys.stdin.readline().split())) for _ in range(n)] # time taken, deadline

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

def solve(jobs):
	total = 0
	for time, deadline in jobs:
		total += time
		if total >  deadline:
			return False
	return True
print("Yes" if solve(jobs) else "No")

Submission status: Accepted

Solution code:
from operator import itemgetter

n = int(input())
a = []
res = ('Yes')
for i in range(n):
    a.append(list(map(int,input().split())))

a.sort(key=itemgetter(1))
suma = 0
for i in range(0,n):
    suma += a[i][0]
    if suma > a[i][1]:
        res = ('No')
        break


print(res)

Submission status: Accepted

Solution code:
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
AB.sort(key = lambda x:x[1])
s = 0
for ab in AB:
  s += ab[0]
  if s <= ab[1]:
    pass
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve(string):
    n, *ab = map(int, open(0).read().split())
    ab = sorted(zip(*[iter(ab)] * 2), key=itemgetter(1))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    print(solve(""))

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))
    for task, deadline in TD:  # check all tasks greedily
        cur += task
        if cur > deadline:  # fail to finish a task within its deadline
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab[::-1])] * 2))
    past = 0
    for b, a in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=itemgetter(1))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
from itertools import accumulate


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])
    a = [a for a, b in ab]
    b = [b for a, b in ab]
    *a, = accumulate(a)
    return "No" if any([_a > _b for _a, _b in zip(a, b)]) else "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1])
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab)] * 2), key=lambda x: (x[1], x[0]))
    past = 0
    for a, b in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab.sort(key=lambda p:p[1])
    t = 0
    for a,b in ab:
        t += a
        if t > b:
            print("No")
            break
    else:
        print("Yes")
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
from itertools import accumulate as acc
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    T, D = zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))
    flg = all(t <= d for t, d in zip(acc(T), D))  # all tasks finish within a deadline?
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
from itertools import accumulate as acc
from operator import itemgetter as gt


def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=gt(1))
    T, D = zip(*A)  # tasks, deadlines
    # all tasks finish within each deadline?
    flg = all(t <= d for t, d in zip(acc(T), D))
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    cur, TD = 0, sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1))
    for task, deadline in TD:  # check all tasks greedily
        cur += task
        if cur > deadline:  # fail to finish a task within its deadline
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
from itertools import accumulate
from operator import itemgetter as gt


def main():
    N, *AB = map(int, open(0).read().split())
    T, D = zip(*sorted([(i, j) for i, j in zip(*[iter(AB)] * 2)], key=gt(1)))
    T = list(accumulate(T))
    flg = all(t <= d for t, d in zip(T, D))  # all tasks finish within each deadline?
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
lst = []#lst[0]=time,lst[1]=limitatiom
for _ in range(n):
    lst.append(list(map(int,input().split())))

lst.sort(key=lambda x: x[1])
sum_time = 0
for time,limitation in lst:
    sum_time+=time
    if sum_time<=limitation:pass
    else:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
d_line = []
for i in range(n):
    a, b = map(int, input().split())
    d_line.append([a, b])
d_line.sort(key = lambda x:-x[1])
time = d_line[0][1] - d_line[0][0]
for i, j in d_line[1:]:
    time = min(time,j)
    if time - i < 0:
        print('No')
        exit()
    time -= i
print('Yes' if time >= 0 else 'No')

Submission status: Accepted

Solution code:
n = int(input())
l = []
c = 0
d = 0
for _ in range(n):
    a,b = map(int,input().split())
    l.append([b,a])
l = sorted(l)


for i in range(0,n):
    if l[i][0] < d + l[i][1]:
        c = 1
        break
    else:
        d = d+ l[i][1]
        continue
if c == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
from collections import deque
import sys
n = int(input())
q = [None]*n
for i in range(n):
    q[i] = tuple(map(int, input().split()))
q = sorted(q, key = lambda x: x[1])
q = deque(reversed(q))
job = q.popleft()
day = job[1] - job[0]
if n == 1:
    if day >= 0:
        print("Yes")
    else:
        print("No")
    sys.exit()

while q:
    job = q.popleft()
    if job[1] < day:
        day = job[1] - job[0]
    else:
        day -= job[0]
    if day < 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ab=sorted([list(map(int,input().split())) for i in range(n)],key = lambda x:x[1])
s=[0]
for i in range(n):
    s.append(s[i]+ab[i][0])
if all(s[i+1] <= ab[i][1] for i in range(n)):
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

w=0
t=0
ans='Yes'
for a,b in ab:
    w+=a
    if b<w:
        ans='No'
    
print(ans)

Submission status: Accepted

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

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

w=0
t=0
ans='Yes'
for a,b in ab:
    w+=a
    if b<w:
        ans='No'
    
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappop, heappush
import sys

N = int(input())
hq = []
for i in range(N):
    heappush(hq, tuple(reversed(list(map(int, input().split())))))
cnt = 0
for i in range(N):
    b, a = heappop(hq)
    cnt += a
    if cnt > b:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

q = []
for _ in range(N):
    val = list(map(int, input().split()))
    # heappush(q, val, lambda x:x[1])
    q.append(val)

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

# solve
cur = 0
for assign, limit in q:
    cur += assign
    if limit < cur:
        print("No")
        exit()

print("Yes")

# while not q.empty():
    # assign, limit = q.heappop()

Submission status: Accepted

Solution code:
N = int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]
A = sorted(A,key= lambda x: x[1])
#A =  sorted(A,key= lambda x: x[0])
#print(A)
ans = 0
for i in range(N):
  ans += A[i][0]
  if ans>A[i][1]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
a=[]
b=[]
xa=[]
xb=[]
y=[]
for i in range (0,N):
    c,d=(int(x) for x in input().split(" "))
    xa.append(c)
    xb.append(d)
     
z=np.argsort(xb)

for i in range (0,N):
    a.append(xa[z[i]])
    b.append(xb[z[i]])
for i in range (0,N):
    if i==0:
      	y.append(a[0])
    else:
      	y.append(a[i]+y[i-1])
def check(i,a,b):
    if b[i]>=y[i]:
        return True
    else:
        return False
def final_check(a,b,N):
    for i in range (0,N):
        if check(i,a,b)==False:
            return "No"
    return "Yes"
print (final_check(a,b,N))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N)]

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

    print("Yes")  

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
AB = [[0]*2 for i in range(N)]

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

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

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

print("Yes")

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
dic_work = {}
for i in range(N):
    a = [int(i) for i in input().split()]
    dic_work[i] = a

dic_work = sorted(dic_work.items(), key=lambda x: x[1][1])

time = 0
for i, dic in dic_work:
    time += dic[0]
    if time > dic[1]:
        print("No")
        sys.exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    jobs = [tuple(map(int, input().split())) for _ in range(N)]
    jobs.sort(key=lambda x: x[1])
    jobs = deque(jobs)

    cur_time = 0
    while jobs:
        job = jobs.popleft()
        if job[1] < cur_time + job[0]:
            print("No")
            return 0
        else:
            cur_time += job[0]
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  a=[0]*n
  b=a[:]
  for i in range(n):
    a[i],b[i]=map(int,input().split())
  b,a=zip(*sorted(zip(b,a)))
  t=0
  for (i,j) in zip(a,b):
    t+=i
    if t>j:
      print("No")
      return
  print("Yes")
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n = inp()
tasks = []
cnt = 0
for i in range(n):
    a,b = inpl()
    tasks.append([a,b,abs(a-b)])
tasks.sort(key=lambda x:x[1])

for task in tasks:
    cnt += task[0]
    if cnt > task[1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline()[:-1]
n=int(input())
data=[tuple(map(int,input().split())) for i in range(n)]
data.sort(key=lambda tup:tup[1])
time=0
for offer in data:
	time+=offer[0]
	if time > offer[1]:
		print('No')
		break
else:print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

task_list = []

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

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

current = 0

for task in task_list:
    current += task[0]
    if current > task[1]:
        print("No")
        exit()

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.sort(key=itemgetter(1))
time = 0
ret = 'Yes'
for i in range(n):
    time += abList[i][0]
    if time > abList[i][1]:
        ret = 'No'
        break
print(ret)

Submission status: Accepted

Solution code:
N = int(input())
W = [[0, 0] for _ in range(N)]
for i in range(N):
  A, B = map(int, input().split())
  W[i] = [B, A]
W.sort()
t = 0
for b, a in W:
  if b < t + a:
    print('No')
    break
  t += a
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
    x, y = map(int, input().split())
    a.append([y, x])
a.sort()
r = 0
for i, j in enumerate(a):
    r += j[1]
    if r > j[0]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

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

def ans(works):
    time = 0
    for work in works:
        time += work[0]
        if time > work[1]:
            print("No")
            return
    print("Yes")
    return

ans(works)

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]-x[0]) # B-Aが小さい順にソート
AB = sorted(AB, key=lambda x: x[1]) # B-Aが同じ値の時はBが小さい順に並び替え
t = 0

for i in range(N):
    if t <= AB[i][1] - AB[i][0]: # B-A以下のとき
        t += AB[i][0]
        continue
    else:
        print('No')
        break
else:
    if t <= AB[N-1][1]:
        print('Yes')
    else:
        print('No')

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]-x[0]) # B-Aが小さい順にソート
AB = sorted(AB, key=lambda x: x[1])
t = 0

for i in range(N):
    if t <= AB[i][1] - AB[i][0]: # B-A以下のとき
        t += AB[i][0]
        continue
    else:
        print('No')
        break
else:
    if t <= AB[N-1][1]:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
	a, b = map(int, input().split())
	if b in d:
		d[b].append(a)
	else:
		d[b] = [a]
dk = sorted(d)
t, o = 0, "Yes"
for k in dk:
	if t+sum(d[k]) > k:
		o = "No"
		break
	t += sum(d[k])
print(o)

Submission status: Accepted

Solution code:
n = int(input())
c = []
for i in range(n):
    a,b = map(int,input().split())
    c.append((b,a))
c.sort()
time = 0
f = True
for d,t in c:
    time+=t
    if time>d:
        f = False
        break
if f:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
from math import ceil
from operator import itemgetter as get

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

def iinput():
    return int(input())

def finput():
    return float(input())

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

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nok(a, b):
    m = a * b
    while a != 0 and b != 0:
        if a > b:
            a %= b
        else:
            b %= a
    return m // (a + b)    


def main():
    n = iinput()
    q, res = [], 0
    for i in range(n):
        q.append(tuple(rinput()))
    q = sorted(q, key = get(1))
    for i, v in q:
        res += i
        if res > v:
            print("No")
            return 0
    print("Yes")
main()

Submission status: Accepted

Solution code:
N = int(input().strip())
AB = []
for i in range(N):
    AB.append(tuple(map(int, input().strip().split())))
AB.sort(key=lambda x: x[1])
t = 0
a = []
for i in AB:
    t += i[0]
    if t > i[1]:
        a.append("NO")

if "NO" in a:
    print("No")
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 = 0
over_flag = False
for i in range(N):
    A, B = AB[i]
    time += A
    if time > B:
        over_flag = True
        break
if over_flag:
    print('No')
else:
    print('Yes')

Submission status: Accepted

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

n = int(input())
a_list = []
b_list = []
for _ in range(n):
    tmp_a, tmp_b = map(int, input().split())
    a_list.append(tmp_a)
    b_list.append(tmp_b)

z = zip(b_list, a_list)
z = sorted(z)
b_list, a_list = zip(*z)

count = 0
flag = True
for a, b in zip(a_list, b_list):
    count += a

    if b < count:
        flag = False
        break

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab = sorted(ab, key=lambda x: x[1])
    t = 0
    for a, b in ab:
        t += a
        if t > b:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

N = int(input())
AB = [0]*N
for i in range(N):
    AB[i] = [int(j) for j in input().split()]
second = lambda val:val[1]
AB.sort(key = second)

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

Submission status: Accepted

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

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

suma = 0
flg = 1
for i in range(n):
    if a[i][1] >= a[i][0]+suma:
        suma = suma + a[i][0]
    else:
        flg = 0
        break  

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

Submission status: Accepted

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

time = ab[0][1] - ab[0][0]
for a,b in ab[1:]:
    time = min(time, b)
    time -= a

print("No" if time < 0 else "Yes")

Submission status: Accepted

Solution code:
N = int(input())
T = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x:x[1])
now = 0
for a, b in T:
    if now + a <= b:
        now += a
    else:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
#りゅうせいの解答3
N = int(input())
task_list = [list(map(int, input().split())) for i in range(N)]

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

j = 0
while(j < N):
    x = task_list[j]
    time += x[0]
    if time > x[1]:
        flag = False
        break
    j += 1

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答2 正解
# N = int(input())
# task_list = [list(map(int, input().split())) for i in range(N)]
#
# task_list.sort(key=lambda task_list: task_list[1])
# time = 0
# flag = True
#
# for i in range(N):
#     x = task_list[i]
#     time += x[0]
#     if time > x[1]:
#         flag = False
#         break
#
# if flag:
#     print("Yes")
#
# else:
#     print("No")




#りゅうせいの解答1　実行時エラー(exit(1)が原因）、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")

Submission status: Accepted

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

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

for i in range(N):
    x = task_list[i]
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答1　実行時エラー、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())

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

    curr = 0
    while len(q) > 0:
        b, a = heappop(q)
        curr += a
        if curr > b:
            print("No")
            return
    print("Yes")
    
resolve()

Submission status: Accepted

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

def main():
    N = int(input())
    Q = []
    for _ in range(N):
        Q.append(list(map(int, input().split())))
    Q = sorted(Q, key=lambda x:x[1], reverse=True)
    t = Q[0][1]
    for q in Q:
        if t > q[1]:
            t = q[1]
        t -= q[0]
    if t >= 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from operator import itemgetter

N = int(input())
W = [list(map(int,input().split())) for i in range(N)]
W.sort(key=itemgetter(1))
time = W[0][0]
if time > W[0][1]:
    print('No')
    exit()
else:
    for i in range(1, N):
        w = W[i]
        time = time + w[0]
        if time > w[1]:
            print('No')
            exit()
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])
t = 0
for i in range(N):
    t += A[i][0]
    if t > A[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    task = []
    for _ in range(N):
        a, b = map(int, input().split())
        task.append([a, b])
    task = sorted(task, key = lambda x: x[1])
    cur = 0
    for a, b in task:
        if cur + a > b:
            return "No"
        cur += a
    return "Yes"


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

Submission status: Accepted

Solution code:
#131d
N = int(input())
lst = []
for i in range(N):
    a, b = map(int, input().split())
    lst.append([b, a])
lst = sorted(lst)

lim = 0
time = 0
flag = 0
for i in lst:
    lim = i[0]
    if time + i[1] <= lim:
        time += i[1]
    else:
        flag = 1
        break
if flag == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

# print(ab_list)

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

time = 0
for a, b in ab_list:
  time = time + a
  if time > b:
    print("No")
    exit()
    
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
b,a=map(list, zip(*sorted(zip(b,a))) )
s=0
for i in range(n):
    s+=a[i]
    if s>b[i]:
        print("No")
        break
else:print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N = int(input())

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

    work.sort(key=lambda x: x[1])
    now = 0
    for a, b in work:
        now += a
        if now > b:
            print("No")
            return

    print("Yes")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

works = defaultdict(int)
n = int(input())
for i in range(n):
    time, limit = map(int, input().split())
    works[limit] += time

now = max(works)
for limit in sorted(works.keys(), reverse=True):
    if limit < now:
        now = limit
    now -= works[limit]

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