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:
import numpy as np
n = int(input())
ab = np.zeros((n, 2))
for i in range(n):
    l = list(map(int, input().split()))
    ab[i, :] = l
ab = ab[np.argsort(ab[:, 1])]
a_cum = np.cumsum(ab[:, 0])
for i in range(n):
    if a_cum[i] > ab[i, 1]:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
BA = []
for i in range(N):
    A, B = map(int, input().split())
    BA.append([B, A])
BA = sorted(BA)
TIME = 0
for i in BA:
    TIME += i[1]
    if TIME > i[0]:
        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 a, b in A:
    t += a
    if t > b:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
N = int(input())

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

#print(work)

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]
    total_time = 0
    for time, deadline in sorted(AB, key=lambda x: x[1]):
        total_time += time
        if total_time > deadline:
            print('No')
            break
    else:
        print('Yes')
main()

Submission status: Accepted

Solution code:
n = int(input())
li = []
for i in range(n):
    a,b = map(int,input().split())
    li.append([a,b])
li = sorted(li,key = lambda x:x[1])
ok = True
sa = 0
for i in range(n):
    #print(li[i])
    f,s = li[i]
    sa += f
    if sa > s:
        ok = False
print('Yes' if ok else 'No')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


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


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

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

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n = ii()
l = []
for _ in range(n):
    l.append(iil())

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

time = 0

for item in l:
    time += item[0]
    if time <= item[1]:
        continue
    else:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
import sys
import numpy as np

n = int(input())
tasks = np.fromstring(sys.stdin.read(), sep=' ').reshape((n, 2))
a = tasks[:, 0]
b = tasks[:, 1]
i = b.argsort()
print('Yes' if (np.add.accumulate(a[i]) <= b[i]).all() else 'No')

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
works = []
for i in range(N):
    a, b = getNM()
    works.append([a, b])
works.sort(key = lambda i: i[1])

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
task = list()
for _ in range(N):
  task.append(list(map(int,input().split())))
task.sort(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())
time = 0
A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([b,a])
A.sort()
for i in range(N):
    time += A[i][1]
    if time > A[i][0]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

deadline=0
now=0
for i in range(n):
    now += task[i][0]
    deadline = task[i][1]
    if now > deadline:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
A_B = [[0 for _ in range(2)] for _ in range(N)]
total = 0
res = 'Yes'
for i in range(N):
  A_B[i][0], A_B[i][1] = map(int, input().split(' '))
A_B.sort(key=lambda x: x[1])
for i in range(N):
  total += A_B[i][0]
  if total > A_B[i][1]:
    res = 'No'
    break
print(res)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N =  I()
L = ILL(N)

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

now = 0
for a,b in L:
  now += a
  if now>b:
    PE("No")
P("Yes")

Submission status: Accepted

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

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


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

weight = 0
for w, d in ab:
    # print(weight, d)
    weight += w
    if weight > d:
        print("No")
        exit()
# print(weight, d)
print("Yes")

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

S=0
ans="Yes"
for i in range(N):
    S+=task[i][1]
    if S>task[i][0]:
        ans="No"
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

now = 0

for a, b in ab:
    now += a
    if now > b:
        print("No")
        sys.exit()

print("Yes")

Submission status: Accepted

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

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

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

T = 0

for AB in L:
  T += AB[0]
  if T > AB[1]:
    print("No")
    exit()

print("Yes")

Submission status: Accepted

Solution code:
n=int(input())

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

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

t = 0
for a,b in tmp:
    t+=a
    if b < t:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

#print(job)
job.sort(key=lambda x: x[1])

#print(job)
time = 0

for i in range(n):
  time += job[i][0]
  #print("time  " + str(time) +  "  jobnumber " + str(i+1))
  if time > job[i][1]:
    print("No")
    quit()
print("Yes")

Submission status: Accepted

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

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

    



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
dct = {}
falseflag = 0
now = 0
for i in range(N):
  A,B = list(map(int, input().split()))
  if( B not in dct):
    dct[B] = [A]
  else:
    dct[B].append(A)
worklist = sorted(dct.items())
for i in range(len(worklist)):
  now += sum(worklist[i][1])
  if(now > worklist[i][0]):
    falseflag = 1
    break
if(falseflag==0):
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N = ri()
d = [ri_() for i in range(N)]
d.sort(key=itemgetter(1))
sm = 0
for di in d:
    sm += di[0]
    if sm > di[1]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    AB = []
    for _ in range(N):
        A, B = map(int, readline().split())
        AB.append((A,B))
    AB.sort(key=lambda x:x[1])
    time_count = 0
    for i in range(N):
        A = AB[i][0]
        B = AB[i][1]
        time_count += A
        if time_count>B:
            print('No')
            break
        else:
            continue
    else:
        print('Yes')

if __name__ == '__main__':
    main()

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,s=0,0
for a,b in ab:
  t=b
  s+=a
  if s<=t:
    pass
  else:
    print("No")
    exit(0)
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])

cost = [0 for i in range(n+1)]
time = [0 for i in range(n+1)]
for i in range(1,n+1):
  cost[i] = cost[i-1] + a[i-1][0]
  time[i] = a[i-1][1]

flag = True
for c, t in zip(cost, time):
  if c > t:
    flag = False
    break
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
N = int(input())
w = [list(map(int, input().split())) for i in range(N)]
w.sort(key = lambda w : w[1])
t = 0
for i in range(N):
    t += w[i][0]
    if t > w[i][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
from sys import exit

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

total = 0
for a,b in ab:
    total += a
    if total <= b:
        continue
    else:
        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()

t = 0
ck=0

for i in range(N):
  a = arr[i][0]
  b = arr[i][1]
  t += b  
  if t > a:
    ck = 1

print("Yes" if ck == 0 else "No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = []
b = []

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

works = []

for i in range(n):
    works.append((b[i], a[i]))

works.sort()

t = 0
end = False

for b, a in works:
    t += a
    if t > b:
        print('No')
        end = True
        break

if not end:
    print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq 
n = int(input())
li = []
heapq.heapify(li)
for i in range(n):
    a,b = map(int,input().split())
    heapq.heappush(li,(b,a))
t = 0
while li:
    b,a = heapq.heappop(li)
    t+=a
    if t>b:
        print('No');exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

    jobs = []
    for i in range(N):
        aa, bb = map(int, input().split())
        jobs.append([aa, bb])

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

    now = 0
    for job in jobs:
        now += job[0]
        limit = job[1]
        if now > limit:
            print('No')
            return

    print('Yes')


resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


mod = 10 ** 9 + 7
N = int(input())
A, B = [0]*N, [0]*N
time = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i] = a
    B[i] = b

tmp = zip(B, A)
tmp = sorted(tmp)
for b, a in tmp:
    time += a
    if (time > b):
        print('No')
        exit()
print('Yes')
# for deadline in sorted(cost.keys()):
#     time += cost[deadline]
#     print(deadline)

Submission status: Accepted

Solution code:
def check():
    N = int(input())
    X = [list(map(int, input().split())) for _ in range(N)]
    X.sort(key=lambda x:x[1])
    now = 0
    for a,b in X:
        now += a
        if now>b:
            return 'No'
    return 'Yes'
print(check())

Submission status: Accepted

Solution code:
n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1])
now = 0
for i in range(n):
    a, b = ab[i]
    now += a
    if b < now:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    AB=[tupin() for _ in range(N)]
    AB.sort(key=lambda x:x[1])
    #print(AB)
    time=0
    for i in range(N):
        time+=AB[i][0]
        if time>AB[i][1]:
            print("No")
            return
    print("Yes")
        
#%%submit!
resolve()

Submission status: Accepted

Solution code:
from operator import itemgetter

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

ab = sorted(ab,key=itemgetter(1),reverse = False)

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

Submission status: Accepted

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))
import fractions

n=int(input())
a=[input_list() for _ in range(n)]
a.sort(key=lambda x:x[1])
cal=0
for each in a:
    v=each[0]
    cal+=v
    if cal>each[1]:
        print("No")
        exit()


print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
arr = []
for i in range(n):
    a = list(map(int,input().split()))
    a.reverse()
    arr.append(a)
arr.sort()
tot = 0
for ab in arr:
    tot += ab[1]
    if tot>ab[0]:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())

jobs = [None]*n
for i in range(n):
  a, b = map(int, input().split())
  jobs[i] = (b, a)

jobs.sort()

ans = True
sub = 0
for i in range(n):
  b, a = jobs[i][0], jobs[i][1]
  sub += a
  if sub > b:
    ans = False
    break

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

Submission status: Accepted

Solution code:
n=int(input())
h=[]
for i in range(n):
    a,b=map(int,input().split())
    h.append((a,b))
h.sort(key=lambda x: x[1])
s=0
for i in range(n):
    s+=h[i][0]
    if h[i][1]<s:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

BA_dict = dict()

for i in range(N):
    A,B = map(int, input().split())
    
    if B not in BA_dict:
        BA_dict[B] = list()
        
    BA_dict[B].append(A)
    
#単純に締め切り時間が早いのから片付ける
BA_sorted = sorted(BA_dict.items(), key=lambda x:x[0])

now_time = 0
for BA in BA_sorted:
    deadline = BA[0]
    now_time += sum(BA[1])
    
    if now_time > deadline:
        print("No")
        break
else:
    print("Yes")

Submission status: Accepted

Solution code:
# ABC131 D Megalomania
import itertools

n = int(input())
ab_list = [[None] * 2 for i in range(n)]
for i in range(n):
    ab_list[i] = list(map(int, input().split()))

ab_list.sort(key=lambda x:(x[1]))
ab_list_T = [list(x) for x in zip(*ab_list)]

cum_iter = itertools.accumulate(ab_list_T[0])

flag = True
for i,_ in enumerate(cum_iter):
    if _ > ab_list_T[1][i]:
        flag = False
    
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
p = []
for i in range(n):
    a,b = map(int,input().split())
    p.append([b,a])
p.sort()
q = 1
s = 0
for i in range(n):
    s += p[i][1]
    if p[i][0] >= s:
        continue
    else:
        q = 0
        print('No')
        break
if q == 1:
    print('Yes')

Submission status: Accepted

Solution code:
from operator import itemgetter
n = int(input())
data = []
for i in range(n):
    data.append(tuple(map(int,input().split())))

data.sort(key = itemgetter(1))

m = 0

for i, j in data:
    if m+i <= j:
        m += i
    else:
        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(tuple((a, b)))

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

time = 0
flg = "Yes"
for i in range(len(ws)):
    time += ws[i][0]
    if(time > ws[i][1]):
        flg = "No"
        break
print(flg)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n  = int(input())
#  = map(int, input().split())
ab  = [tuple(map(int, input().split())) for _ in range(n)]
ba = [(b, a) for (a, b) in ab]
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ba = sorted(ba)
#print(ba)

qa = 0
for (b, a) in ba:
    qa += a

    if qa > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

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

N = int(input())

AB = {} # 締め切り: かかる時間


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


time = 0
for s, t in sorted(AB.items(), key=lambda x:x[0]):
    for ti in t:
        time += ti
        if time > s:
            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])
s = 0
for i in ab:
    s += i[0]
    if s > 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]))
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())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(key=lambda x: (x[1], -x[0]))
time = 0
for a, b in AB:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
a = [LI() for _ in range(n)]
a.sort(key = lambda x: x[1])
t = 0
for i in range(n):
    t += a[i][0]
    if t > a[i][1]:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
n = int(input())

works = list()
for num in range(n):
    a = list(map(int, input().split()))
    works.append(a)

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

time = 0
limit = 0

for row in works:
    time += row[0]
    limit = row[1]
    if time > limit:
        print("No")
        exit()

print("Yes")

Submission status: Accepted

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

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

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

print('Yes')

Submission status: Accepted

Solution code:
#d
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[1])
a, b = [list(i) for i in zip(*ab)]
import sys
time_sum=0
limit_sum =0

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

Submission status: Accepted

Solution code:
import sys
N = int(input())
X = [list(map(int, input().split())) for i in range(N)]
X = sorted(X, key=lambda x:x[1])
t = 0
for x in X:
    t += x[0]
    if t > x[1]:
        print('No')
        sys.exit()
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)]
ab = sorted(ab, key=lambda x:x[1])
now = 0
for a, b in ab:
  if now + a <= b:
    now += a
  else:
    print('No')
    exit()
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[0]), reverse=True)
AB = sorted(AB, key=lambda x:(x[1]))
time = 0
for ab in AB:
    time += ab[0]
    if time > ab[1]:
        time = -1
        break

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_d

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])
for i in range(n - 1):
    work[i + 1][0] += work[i][0]

for i in range(n):
    if work[i][0] <= work[i][1]:
        continue
    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)]
d=[]
for i in range(n):
  x,y=map(int,input().split())
  d.append([y,x])
d.sort()
time=0
flag=True
for i in range(n):
  time+=d[i][1]
  if time>d[i][0]:
    flag=False
    break
if flag==True:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append([A, B])
AB.sort(key=itemgetter(1))
cnt = 0
for a, b in AB:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
ab_list = [list(map(int,input().split())) 
           for nesya in range(n)]
ab_list = sorted(ab_list,key=lambda x: (x[1],x[0]))
time = 0
for ab in ab_list:
  a = ab[0]
  b = ab[1]
  time += a
  if time <= b:
    pass
  else:
    time = -1
    print('No')
    break
if time > -1:
  print('Yes')

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
b_ = np.argsort(np.array(B))

t = 0
for i in b_:
    t += A[i]
    if t > B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
mat.sort(key=lambda x: x[1])
t = 0
for task in mat:
    due = task[1] - t
    if due < task[0]:
        print('No')
        exit()
    else:
        t += task[0]
print('Yes')

Submission status: Accepted

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

res = 0
for j, k in task:
    res += j
    if res > k:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import sys
N = int(input())
job = []
for _ in range(N):
  job.append(list(map(int,input().split())))
  
job.sort(key=lambda x:x[1])
b = 0
for i in range(N):
  if job[i][1]-job[i][0]< 0:
    print('No')
    sys.exit()
  if i < N-1:
    b += job[i][0]
    job[i+1][1] -= b
print('Yes')