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())
work = sorted([list(map(int, input().split()))
               for i in range(n)], key=lambda x: x[1])

t = 0
flag = True
for w in work:
    t += w[0]
    if t > w[1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 締切の近いものから詰め込む

import numpy as np

N = int(readline())
AB = np.array(read().split(),np.int64)

A = AB[::2]; B = AB[1::2]

ind = B.argsort(); A = A[ind]; B = B[ind]

answer = 'Yes' if np.all(A.cumsum() <= B) else 'No'
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n=int(input())
ab=[]
for i in range(n):
    ab.append(tuple(map(int,input().split())))
ab.sort(key=lambda tup:tup[1])
time=0
for a,b in ab:
    time+=a
    if time>b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
n = int(input())
time = [list(map(int,input().split())) for i in range(n)]
time.sort(key=lambda x: x[1])
sum = 0
for i in range(n):
    sum += time[i][0]
    if sum > time[i][1]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

#dictは同じキーが登場すると上書きしてしまうので工夫が必要
#タプルのリストのままやるぞ

lst.sort()

#print(lst)
#=>[(4, 2), (8, 1), (9, 1), (9, 4), (12, 3)]
#(deadline,time)の順で配置されている

result='Yes'
time=0 #i番目にやる仕事まで終わらせるのにかかる時間

for i in range(n):
	time+=lst[i][1]
	if time>lst[i][0]:
		result='No'

print(result)

Submission status: Accepted

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

#dictは同じキーが登場すると上書きしてしまうので工夫が必要
#タプルのリストのままやるぞ

lst.sort()

#print(lst)
#=>[(4, 2), (8, 1), (9, 1), (9, 4), (12, 3)]
#(deadline,time)の順で配置されている

result='Yes'
time=0 #i番目にやる仕事まで終わらせるのにかかる時間

for i in range(n):
	time+=lst[i][1]
	if time>lst[i][0]:
		result='No'
		break;

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
AB_list = []
for i in range(N):
    AB = list(map(int, input().split()))
    AB_list.append(AB)
    
AB_list = sorted(AB_list, key=lambda x:x[1])
sum_worktime = 0
flag = True
for i in range(N):
    sum_worktime += AB_list[i][0]
    if sum_worktime > AB_list[i][1]:
        flag = False
        break

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

Submission status: Accepted

Solution code:
from sys import exit

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

t = 0
AB.sort(key=lambda x: x[1])
for A, B in AB:
    t += A
    if t > B:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from sys import exit

n = int(input())
data = [[int(j) for j in input().split()] for i in range(n)]

t = 0
data.sort(key=lambda x: x[1])
for d in data:
    t += d[0]
    if t > d[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    C = []
    for i in range(N):
        A, B = map(int, input().split())
        C.append([B,A])

    sort_C = sorted(C)

    s = 0
    for c in sort_C:
        if s + c[1] <= c[0]:
            s += c[1]
        else:
            print('No')
            exit()

    print('Yes')

main()

Submission status: Accepted

Solution code:
#開始限界が早い順でよいか

import sys

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

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


J.sort()

time = 0

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

print("Yes")

Submission status: Accepted

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = []
for i in range(n):
    a.append(na())
a.sort(key=lambda x: x[1])
time = 0
ans = "Yes"
for ai in a:
    time += ai[0]
    if time > ai[1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
import sys

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

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

total = 0
# flag = True 
for aabb in ab:
    total += aabb[0] 
    if total > aabb[1]:
        print("No")
        sys.exit()
        break

print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
task = [list(map(int, input().split())) for _ in range(n)]
task.sort(key=itemgetter(1))
time = 0
flag = 0
for i in range(n):
    time += task[i][0]
    if time > task[i][1]:
        flag = 1
if flag == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())

l=[]

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

l.sort()

now=0

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

Submission status: Accepted

Solution code:
n = int(input())
tlm = [tuple(map(int, input().split())) for _ in range(n)]
# time/limit

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

flg = True
cur = 0
for t, lm in tlm:
    cur += t
    if cur > lm:
        flg = False
        break

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

Submission status: Accepted

Solution code:
n=int(input())
a=[]
sum=0
j='Yes'
for _ in range(n):
    a.append(list(map(int,input().split())))
a.sort(key=lambda i: i[1])
for i in range(len(a)):
    sum += a[i][0]
    if sum > a[i][1]:
        j='No'
print(j)

Submission status: Accepted

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

time = 0

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
li = []
work = []
for i in range(n):
    a,b = map(int, input().split())
    li.append((b,b-a,i))
    work.append(a)
li.sort()
now = 0
for bb,s,w in li:
    if now > s:
        print("No")
        exit()
    else:
        now += work[w]
print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from heapq import heappop, heappush

sys.setrecursionlimit(10 ** 7)


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


def solve(N: int, A: "List[int]", B: "List[int]"):
    task_index = {}
    for i in range(N):
        if B[i] in task_index:
            task_index[B[i]].append(A[i])
        else:
            task_index[B[i]] = [A[i]]

    sum_task_time = sum(A)
    dead_line_pool = []
    for i in B:
        heappush(dead_line_pool, -i)

    for _ in range(N):
        last_dead_line = -heappop(dead_line_pool)
        if sum_task_time > last_dead_line:
            print('No')
            return
        else:
            sum_task_time -= task_index[last_dead_line].pop()

    print('Yes')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [None]*N
for i in range(N):
  A[i] = list(map(int,input().split()))
A.sort(key = lambda x:x[1])
B = [0]*len(A)
C = [0]*len(A)
for b in range(len(A)):
  B[b] = A[b][0]
for c in range(len(A)):
  C[c] = A[c][1]
jud = 'Yes'
Sum = 0
for j in range(N):
  Sum += B[j]
  if Sum > C[j]:
    jud = 'No'
    #print(C[j])
    #print(B[:j+1])
print(jud)

Submission status: Accepted

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

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

for i in range(n):
  a_sum += lst[i][0]
  if lst[i][1] < a_sum:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
ws = sorted([[int(i) for i in input().split()] for _ in range(n)], key=lambda x: -x[1])
t = ws[0][1]
for w in ws:
	if t > w[1]:
		t = w[1] - w[0]
	else:
		t -= w[0]
print('Yes' if t >= 0 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])

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

print("Yes")

Submission status: Accepted

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

flag=True
time=0
for work in w:
    time+=work[0]
    if time>work[1]:
        flag=False
        break
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
li_2 = sorted(li, key=lambda x: x[1])
time = 0
for i in range(n):
  time += li_2[i][0]
  if time <= li_2[i][1]:
    if i == n-1:
      print("Yes")
  elif time > li_2[i][1]:
    print("No")
    break;

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
tasks = []
for _ in range(n):
    a,b = map(int,input().split())
    tasks.append((b,a))
tasks.sort()

now = 0
for (b,a) in tasks:
    now += a
    if b<now:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import heapq

N = int(input())
tasks = []
for _ in range(N):
  a,b = map(int,input().split())
  if b-a < 0:
    print('No')
    exit()
  else:
    heapq.heappush(tasks,[b,-a])
    
day = 0
while len(tasks) != 0:
  b, neg_a = heapq.heappop(tasks)
  if day - neg_a > b:
    print('No')
    exit()
  else: day -= neg_a
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = []
t = 0

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

Submission status: Accepted

Solution code:
def main():

    N = int(input())
    A = []
    for _ in range(N):
        B = list(map(int, input().split()))
        A.append(B)
    A.sort(key=lambda x: x[1])
    time = 0
    for i in range(N):
        time += A[i][0]
        if time > A[i][1]:
            print("No")
            exit()
        else:
            continue
    print("Yes")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import heapq
import sys
input = sys.stdin.readline
 
 
def main():
    N = int(input())

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

    t = 0
    while len(Q)!=0:
        b, a = heapq.heappop(Q)
        t += a
        if t>b:
            print('No')
            return
    print('Yes')

 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq
import copy
import bisect
from collections import deque

n = int(input())
a = []
b = []
tmp_a = []
tmp_b = []
flag = True

for _ in range(n):
	a_dash,b_dash = map(int,input().split())
	tmp_a.append(a_dash)
	tmp_b.append(b_dash)

k = zip(tmp_b,tmp_a)
sorted_k = sorted(k)
for b_dash,a_dash in sorted_k:
	a.append(a_dash)
	b.append(b_dash)

t = 0
qa = deque(a)
qb = deque(b)

for i in range(n):
	minimum_a = qa.popleft()
	minimum_b = qb.popleft()
	t += minimum_a
	if t > minimum_b:
		flag = False
		break

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

Submission status: Accepted

Solution code:
import sys

def main():
    def input():
        return sys.stdin.readline()[:-1]
    N = int(input())
    L = [list(map(int,input().split())) for k in range(N)]
    L = sorted(L,key = lambda x: (x[1],x[0]))
    t = 0
    for e in L:
        if t+e[0] > e[1]:
            print("No")
            exit(0)
        else:
            t += e[0]
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    L = [list(map(int,input().split())) for k in range(N)]
    L = sorted(L,key = lambda x: (x[1],x[0]))
    t = 0
    for e in L:
        if t+e[0] > e[1]:
            print("No")
            exit(0)
        else:
            t += e[0]
    print("Yes")
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
ab = [tuple(li()) for _ in range(n)]

ab.sort(key=lambda x: x[1])
cur = 0
ok = True

for ai, bi in ab:
    cur += ai
    if cur > bi:
        ok = False
        break

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

Submission status: Accepted

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

tasks = sorted(tasks,key=lambda x: x[1])
total = 0
#print(tasks)
for i in tasks:
  total += i[0]
#  print(total,i[0],i[1])
  if total <= i[1]:
    continue
  else:
    print("No")
    exit()
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])
m = 0
ans = "Yes"
for a,b in AB:
    m += a
    if m > b:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

sum=0

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

cnt = 0
for i in range(N):
    temp = X[i][1]
    cnt += X[i][0]
    if temp < cnt:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

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

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

sum_time = 0
judge = 1 #可
for i in range(N):
  sum_time += work[i][0]
  if(sum_time > work[i][1]):
    judge = 0
    break

if(judge == 0): print('No')
else: 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])
work_time = 0
#print(AB)
for ab in AB:
  deadline = ab[1]
  work_time += ab[0]
  if deadline < work_time:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

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

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

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 sys
input = sys.stdin.readline
n=int(input())

l=[[0,0] for _ in range(n)]
for i in range(n):
    l[i][1],l[i][0]=map(int,input().split())
l.sort()
c=0
for i in range(n):
    c+=l[i][1]
    if l[i][0]<c:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

AB.sort(key=lambda x:x[1])
now = 0
ans = "Yes"
for i in range(N):
    now += AB[i][0]
    if now > AB[i][1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

jobs = sorted(jobs, key = lambda x:x[1])
now = 0
for time, deadline in jobs:
    now += time
    if now > deadline:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = [[int(i) for i in input().split()] for _ in range(n)]
a.sort(key=lambda x: x[1], reverse=True)
b=a[0][1]
for i in a:
    b = min(b, i[1]) - i[0]
if b >= 0:
    print('Yes')
else:
    print("No")

Submission status: Accepted

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

sum = 0
for a,b in AB:
  sum+=a
  if sum>b:
    print("No")
    break
else:
  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])
#print(ab)
k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    #print([k,answer])
    if k>ab[t][1]:
        answer=answer*0
if answer==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.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(0)

print('Yes')

Submission status: Accepted

Solution code:
from sys import stdin, exit
N = int(stdin.readline().rstrip())
AB = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
#D
n=int(input())
data=[]
for i in range(n):
    a,b=map(int,input().split())
    data.append([b,a])
data.sort()
time=0
for i in range(n):
    time+=data[i][1]
    if time>data[i][0]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = sorted(LIR(n), key=lambda x:x[1])
ret = 0
for i in range(n):
    ret += L[i][0]
    if ret > L[i][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
ABs = [list(map(int,input().split())) for _ in range(N)]
ABs.sort(key=lambda x: x[1]) 
time = 0
for i in range(N):
    time += ABs[i][0] 
    if time > ABs[i][1]:
        print('No')
        sys.exit()


print('Yes')

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)


s = sorted(range(len(b)), key=lambda k: b[k])
fl = 0
time = 0
for si in s:
    time += a[si]
    if time > b[si]:
        fl = 1

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

Submission status: Accepted

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

n = int(input())

a_list = []
b_list = []
for i in range(n):
    tmp_a, tmp_b = list(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)

sum_t = 0

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

    if sum_t > b:
        flag = False
        break

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

Submission status: Accepted

Solution code:
import sys
import bisect
import numpy as np
input = sys.stdin.readline
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=[int(x) for x in input().split()]
matrix = np.vstack((np.array(A),np.array(B)))
matrix = matrix[:, np.argsort(matrix[1])]
time=0
capacity=0
for a,b in zip(matrix[0],matrix[1]):
    capacity += (b-time) - a
    time = b
    if capacity <0:
        print('No')
        sys.exit()
    #print(capacity,a,b)
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
task = [list(map(int,input().split())) for i in range(N)]
task.sort(key=lambda a:a[1])
now = limit = 0
for i in range(N):
    limit = task[i][1]
    now += task[i][0]
    if now>limit:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import heapq as hq

n = int(input())

list_A = []
list_B = []
h = []
for i in range(n):
    a, b = map(int, input().split())
    hq.heappush(h, [b, a])

time = 0
for _ in range(n):
    b, a = hq.heappop(h)
    time += a
    if b < time:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

Solution code:
import heapq
import sys
N=int(input())
BA=[]
for i in range(N):
  a,b=map(int,input().split())
  heapq.heappush(BA,[b,a])
time=0
while BA!=[]:
  v=heapq.heappop(BA)
  b1,a1=v[0],v[1]
  time+=a1
  if time>b1:
    print('No')
    sys.exit()   
print('Yes')

Submission status: Accepted

Solution code:
import heapq as hq

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

for i in range(N):
    a, b = [int(_) for _ in input().split()]
    hq.heappush(AB, (b, a))

t = 0
while AB:
    b, a = hq.heappop(AB)
    t += a
#    print(a, b, t)
    if t > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

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


def solve():
    t = 0
    for w in work:
        t += w[0]
        if t > w[1]:
            return False

    return True


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

Submission status: Accepted

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

current = 0

flag = True
for i in range(n):
  if (current + a[i]) > b[i]:
    flag = False
    break
  else:
    current += a[i]
  

if flag:
  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)]
AB_sorted = sorted(AB, key=lambda x:x[1])
s = 0

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

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
dict = defaultdict(list)
for _ in range(N):
    a, b = [int(x) for x in input().split()]
    dict[b].append(a)

total = 0
for k, v in sorted(dict.items()):
    total += sum(v)
    if k < total:
        print("No")
        exit()


print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

class Work():
    """ 仕事クラス """
    def __init__(self, a, b):
        self.need_time = a  # 仕事を終わらせるのに必要な時間
        self.deadline = b   # 締切時刻


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

    works = []  # 仕事をリストにぶちこむ
    for _ in range(N):
        a, b = list(map(int, input().split()))
        works.append(Work(a, b))
    works.sort(key=lambda x: x.deadline)  # 締切が早い順にソート

    # 締切が早いやつから先に仕事を終らせる貪欲法
    now_time = 0  # 現在時刻
    for i in range(N):
        now_time += works[i].need_time
        if now_time > works[i].deadline:
            print("No")
            return
    print("Yes")



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

all_sort = sorted(all)
ruikei = 0
judge = 'Yes'
for item in all_sort:
  ruikei += item[1]
  if ruikei > item[0]:
    judge = 'No'
    break;

print(judge)

Submission status: Accepted

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

class Work():

    def __init__(self, a, b):
        self.need_time = a  # 仕事を終わらせるのに必要な時間
        self.deadline = b   # 締め切り時刻


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

    works = []
    for _ in range(N):
        a, b = list(map(int, sys.stdin.readline().split()))
        works.append(Work(a, b))
    works.sort(key=lambda x: x.deadline)  # 締め切りが早い順にソート

    # 締切が早いやつから先に仕事を終らせる貪欲法
    now_time = 0  # 現在時刻
    for i in range(N):
        now_time += works[i].need_time
        if now_time > works[i].deadline:
            print("No")
            return
    print("Yes")



if __name__ == "__main__":
    solve()

Submission status: Accepted

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