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)]
ab.sort(key=lambda x:x[1])
#print(ab)
tot=0
for i in range(n):
    tot+=ab[i][0]
    if tot>ab[i][1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

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

arr.sort()
time = 0
flag = True
for i in range(n):
    time += arr[i][1]
    if time > arr[i][0]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
import sys
N = int(input())
BA = [None] * N
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    BA[i] = (b, a)
BA.sort()

t = 0
for b, a in BA:
    t += a
    if b < t:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
# Bについてソート
AB = sorted(AB, key=lambda x: x[1])
time = 0
for job in AB:
    # Aを足す
    time += job[0]
    # 期限を過ぎてしまった場合
    if time > job[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
A.sort(key = lambda x: x[1])
su = 0
for i in A:
    su += i[0]
    if su > 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)]
ab.sort(key=lambda x:x[1])
comp = []
for lst in ab:
    comp.append(lst[1])
acc = [0]
for i, v in enumerate(ab):
    acc.append(acc[-1] + v[0])
for x, y in zip(acc[1:], comp):
    if x > y:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

t = 0
for i, (b, a) in enumerate(tsk):
    t += a
    if t > b:
        print('No')
        exit()
else:
    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.sort(key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
ABs = []

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

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

sum = 0
for A, B in ABs:
    sum += A
    if sum > B:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
ABs = []

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

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

sum = 0
for A, B in ABs:
    sum += A
    if sum > B:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
ABs = []

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

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

sum = 0
for pair in ABs:
    sum += pair[0]
    if sum > pair[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter

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

C.sort(key=itemgetter(1))

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

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

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

Submission status: Accepted

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


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    tasks = []

    for i in range(N):
        task = LI()
        tasks.append([task[1], task[0]])
    tasks.sort()

    sum_time = 0

    for task in tasks:
        sum_time += task[1]
        if sum_time > task[0]:
            print("No")
            return

    print("Yes")


main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
from itertools import combinations_with_replacement, product
import numpy as np
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    task=[]
    for _ in range(N):
        A,B=map(int, input().split())
        task.append([A,B])
    task.sort(key=lambda x: x[1])
    task=np.array(task)
    task[:,0]=task[:,0].cumsum()
    if all(task[:,0] <= task[:,1]):
        print('Yes')
    else:
        print('No') 

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N =int(input())
AB = []
for i in range(N):
    a,b = map(np.int64,input().split())
    AB.append((b,a))

AB.sort()
time = np.int64(0)

for b,a in AB:
    if time +a >b:
        print("No")
        exit()
    time +=a
    
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()
time =0

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

Submission status: Accepted

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

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


def solve(N: int, A: "List[int]", B: "List[int]"):
    acc = 0
    for b, a in sorted(zip(B, A)):
        acc += a
        if b < acc:
            return NO
    return YES

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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))
    print(solve(N, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

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])
timer = 0

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

Submission status: Accepted

Solution code:
def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

N = cin()
A = []
for i in range(N):
    in1, in2 = cin()
    A.append([in2, in1])

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

Submission status: Accepted

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

time = 0
for i in range(n):
    simekiri, sigoto = lst[i][0],lst[i][1]
    time += sigoto
    if time <= simekiri:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = [[*map(int, input().split())] for i in range(n)]
s.sort(key=lambda x: x[1])
c = 0
for a, b in s:
    c += a
    if c > b:
        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])
time=0
for A,B in AB:
    time+=A
    if time>B:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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


def main():
    n = int(readline().rstrip())
    A = [list(map(int, readline().rstrip().split())) for _ in range(n)]
    A.sort(key=lambda x: x[1])
    sumTime = 0
    maxTime = 0
    for arr in A:
        maxTime = arr[1]
        sumTime += arr[0]
        if maxTime - sumTime < 0:
            print("No")
            return
    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
d=[]
for _ in range(n):
  a,b=map(int,input().split())
  d+=[(b,a)]
d=sorted(d)
t=0
for i,j in d:
  if j+t>i:
    print('No')
    break
  t+=j
else:print('Yes')

Submission status: Accepted

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

N=int(input().rstrip('\n'))
s = {}
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  if B in s:
    s[B] += A
  else:
    s[B] = A
m = sorted(list(set(s)))
check = 0
used = 0
for i in m:
  used += s[i]
  if used > i:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

Submission status: Accepted

Solution code:
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])
t=0
for i in range(N):
  ab=AB[i]
  t += ab[0]
  if t > ab[1]:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
d = {}
s = 0
for i in range(n):
    a, b = map(int, input().split())
    if b not in d:
        d.update({b:a})
    else:
        d[b] += a
    s += a
key = list(d.keys())
key.sort(reverse = True)
ans = True
for k in key:
    if k < s:
        ans = False
        break
    s -= d[k]
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())

X=[0]*N
for k in range(1,N+1):
    a,b=map(int,input().split())
    X[k-1]=(a,b)

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

D=0
F=True
for (s,t) in X:
    D+=s
    F&=D<=t

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

Submission status: Accepted

Solution code:
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  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])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array([list(map(int,input().split())) for _ in range(n)])
s = np.argsort(A[:,1])
A = A[s]
aa = 0
ans = 'Yes'
for a,b in A:
    aa += a
    if aa > b:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
A = np.array([list(map(int,input().split())) for _ in range(n)])
s = np.argsort(A[:,1])
# B基準でソート
A = A[s]
a = 0
ans = 'Yes'
for i in range(n):
    a += A[i,0]
    b = A[i,1]
    if a > b:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

total = 0
for si in s:
    total += si[0]
    if total > si[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ab = sorted([list(map(int, input().split())) for _ in range(n)], 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:
import sys
N = int(input())
V = [list(map(int, input().split())) for _ in range(N)]
V.sort(key=lambda x: x[1])
s = 0
for v in V:
    s += v[0]
    if s > v[1]:
        print('No')
        sys.exit()
print('Yes')

Submission status: Accepted

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

Time = 0 
for task in T:
    taskTime, deadline = task
    Time += taskTime
    if deadline < Time:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
sa = []
for i in range(n):
  a,b = list(map(int, input().split()))
  if ( a > b ):
    print('No')
    exit()    
  sa.append({'a': a, 'b': b})

sa.sort(key=lambda x: x['b'])

aa = 0
for i in range(n):
  aa = aa + sa[i]['a']
  if (aa > sa[i]['b']):
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
sa = []
for i in range(n):
  a,b = list(map(int, input().split()))
  if ( a > b ):
    print('No')
    exit()    
  sa.append({'a': a, 'b': b})

sa.sort(key=lambda x: x['b'])

aa = 0

for i in range(n):
  aa = aa + sa[i]['a']
  b = sa[i]['b']
  if (aa > sa[i]['b']):
    print('No')
    exit()

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

arr = []

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

arr.sort()

now = 0

for a in arr:
	if now + a[1] > a[0]:
		print("No")
		exit()
	now += a[1]

print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
tasks = [None] * N

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

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

time = 0
for t in tasks:
  if t[1] - t[0] < time:
    print("No")
    break
  time += t[0]
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])
time = 0
 
for A,B in AB:
    time += A
    if time > B:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
time = 0
flag = 0

for _ in range(N):
    a, b = map(int, input().split())
    if b in dic:
        dic[b] += a
    else:
        dic[b] = a

deadlines = sorted(dic.keys())

for dead in deadlines:
    time += dic[dead]
    if time > dead:
        flag += 1

if flag:
    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])
time = 0

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = [list(map(int,input().split())) for _ in range(n)]
s.sort(key=lambda x:(x[1],x[1]-x[0]))
time = 0
ans = 1
for v in s:
  time += v[0]
  if time > v[1]:
    ans = 0
print('Yes' if ans else 'No')

Submission status: Accepted

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

for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
    a += li[0]
    b = max(b,li[1])
    
l = sorted(l, key=lambda x: x[1])
if a > b:
    print('No')
    exit()

count = 0
for i in range(n):
    count += l[i][0]
    if count <= l[i][1]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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


n = int(readline())
ab = [list(map(int, readline().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
cost = 0
for i in range(n):
    cost += ab[i][0]
    if cost > ab[i][1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

now_index = 0
now_time = 0
while now_index < N:
    deadline = ABs[now_index][1]
    now_time += ABs[now_index][0]
    additional_task = 0
    for i in range(now_index+1, N):
        if ABs[i][1] != deadline:
            break
        else:
            now_time += ABs[i][0]
            additional_task+=1
    now_index += 1
    now_index += additional_task
    if now_time > deadline:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
ba=[list(map(int,input().split()))[::-1]for _ in range(N)]
ba.sort()
 
time=0
ans='Yes'
for b,a in ba:
    time+=a
    if time>b:
        ans='No'
print(ans)

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
W = []
for i in range(N):
	a, b = rl()
	W.append((b, a))
W.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

sum1=0
for i in lab:
  sum1+=i[0]
  if sum1>i[1]:
    print('No')
    exit()
    
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
A = [0]*n
B = [0]*n
dica = {}
dicb = {}
for i in range(n):
    A[i],B[i] = map(int,input().split())
    dica[i] = A[i]
    dicb[i] = B[i]

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

time = 0
for i in range(n):
    time += dica[dicb[i][0]]
    if time > dicb[i][1]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    d = []
    for _ in range(n):
        f, s = [int(x) for x in input().split()]
        d.append((s, f))
    d.sort()
    cur = 0
    for b, a in d:
        cur += a
        if cur > b:
            print("No")
            return
    print("Yes")


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Accepted

Solution code:
N = int(input())

tasks = []

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

tasks.sort()

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

Submission status: Accepted

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

sort_AB = sorted(AB, key= lambda x: x[1])
ans = 'Yes'
tmp = 0

for i in range(N):
    tmp += sort_AB[i][0]
    if tmp > sort_AB[i][1]:
        ans = 'No'
        break
        
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    task = [[int(item) for item in input().split()] for _ in range(N)]

    task.sort(key=lambda x:x[1] ,reverse=True)


    res = task[0][1]
    for time, lim in task:
        if res > lim:
            res = lim
            
        res -= time

    print('Yes') if res >= 0 else print('No')

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    ab=[]
    for _ in range(n):
        a,b=map(int,input().split())
        ab.append((a,b))
    return n,ab

def main(n,ab):
    ab.sort(key=lambda x:x[1], reverse=True)
    t=ab[0][1]
    for i in range(n):
        if ab[i][1]<t:
            t=ab[i][1]
        t=t-ab[i][0]
    if t>=0:
        return 'Yes'
    else:
        return 'No'

if __name__=='__main__':
    n,ab=readinput()
    ans=main(n,ab)
    print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    lim = {}
    for i in range(n):
        a,b = map(int,input().split())
        if b not in lim.keys():
            lim[b] = [a]
        else:
            lim[b].append(a)
    time = 0
    for k in sorted(lim.keys()):
        time += sum(lim[k])
        if time<=k:
            continue
        else:
            print('No')
            return
    print('Yes')

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ba.sort()
time = 0
for b, a in ba:
    time += a
    if b < time:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

N =int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
ABS = sorted(AB,key = lambda x:x[1])
now = 0
for i in range(N):
    now += ABS[i][0]
    if now > ABS[i][1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 13, 2020 04:40:02 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from sys import stdin
input = stdin.readline


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

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


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

Submission status: Accepted

Solution code:
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

n=int(input())
AB=[input_array() for _ in range(n)]

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

ans=0
flag=True
for i in sort_AB:
	ans+=i[0]
	if ans > i[1]:
		flag=False
		break

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = list(tuple(map(int, input().split())) for i in range(N)) #改行行列

    S.sort(key=itemgetter(1))
    cur=0
    for a,b in S:
        cur+=a
        if b<cur:
            print('No')
            return
        
        

    print('Yes')




if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
ab = [readInts() for i in range(n)]
ab.sort(key=lambda x:x[1])
now = 0
for i in ab:
  now+=i[0]
  if now<=i[1]:
    pass
  else:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

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

now = 0
for a, b in ablist:
    if now + a <= b:
        now += a
    else:
        print("No")
        break
else:
  print("Yes")

Submission status: Accepted

Solution code:
N=int(input())
d=[]
for _ in range(N):
    d.append(list(map(int,input().split())))
d.sort(key=lambda x:x[1])
sum_d=[0]*N
sum_d[0]=d[0][0]
for i in range(N-1):
    sum_d[i+1]=sum_d[i]+d[i+1][0]

for i in range(N):
    if sum_d[i]>d[i][1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

Work.sort(key=lambda x: x[1])
now = 0
for a, b in Work:
    now += a
    if b < now:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
Z=[]
for i in range(N):
    Z.append(list(map(int,input().split())))
ct=sorted(Z, key=lambda x:x[1])
ans=0
flag=True
for k in ct:
    ans+=k[0]
    if ans<=k[1]:
        continue
    else:
        flag=False
        break
print('Yes' if flag==True else 'No')

Submission status: Accepted

Solution code:
n = int(input())

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

task.sort()
ans = "Yes"
for i in range(n):
    t += task[i][1]
    if task[i][0] < t:
        ans = "No"
        break

print(ans)

Submission status: Accepted

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

cnt = 0
flag = True
for l in li:
  cnt += l[0]
  if cnt > l[1]:
    flag = False
    break
    
if flag:
  print('Yes')
else:
  print('No')

Submission status: Accepted

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

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

ab.sort()

time = 0

for b, a in ab:
    time += a
    if b < time:
        print('No')
        exit()
    
print('Yes')

Submission status: Accepted

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

B=sorted(B)

sumA=0
fin=True
for n in range(N):
    tmp=B[n][1]
    sumA+=A[tmp]
    if sumA>B[n][0]:
        fin=False
        break

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

Submission status: Accepted

Solution code:
# 解法 おそらくアルゴリズムの授業で出た，単純に締め切りが近いものからやっていくのが正しいのではないかと思われる．
#
N = int(input())
AB = []
for _ in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])

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

# 最速でタスクをクリアしつつ，もし最短時間でも締め切りを過ぎた場合はだめ．
now = 0
for ab in AB:
    a,b = ab
    now += a
    if now>b:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
N = int(input())
a, b = [], []
ans = 0

for i in range(N):
    a0, b0 = map(int, input().split())
    a.append(a0)
    b.append(b0)
b, a = zip(*sorted(zip(b, a)))
for i, j in zip(a, b):
    ans += i
    if ans > j:
        print('No')
        sys.exit()
print('Yes')