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: Time Limit Exceeded

Solution code:
n = int(input())

a = []
b = []

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

order = list(range(n))
tmp_b = b[:]

while(True):
    ok = False
    for i in range(n - 1):
        ok = False
        if tmp_b[i] > tmp_b[i + 1]:
            tmp = tmp_b[i]
            tmp_b[i] = tmp_b[i + 1]
            tmp_b[i + 1] = tmp

            tmp = order[i]
            order[i] = order[i + 1]
            order[i + 1] = tmp
            break
        ok = True
    if ok:
        break

available = False

for i in range(1000):

    margin = [0 for i in range(n)]
    now_time = 0
    for i in range(n):
        j = order[i]
        margin[j] = b[j] - (now_time + a[j])
        now_time += a[j]
    
    if min(margin) >= 0:
        available = True
        break
    else:
        min_index = margin.index(min(margin))
        max_index = margin.index(max(margin))

        tmp = order[min_index]
        order[min_index] = order[max_index]
        order[max_index] = tmp


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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def insert(ab, lol) :
    for j in range(len(lol)) :
        if ab[1] > lol[j][1] :
            pass
        else :
            return lol[:j] + [ab] + lol[j:]
    else :
        return lol + [ab]

ablist = []
for i in range(n) :
    ab = list(map(int, input().split()))
    ablist = insert(ab, ablist)
wa = 0
for i in ablist :
    wa += i[0]
    if wa > i[1] :
        print("No")
        break
else :
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import fractions

#inp = [int(i) for i in input().split()]
inp = int(input())

task = []
for e in range(inp):
    task.append([int(i) for i in input().split()])

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

    ti = 0
for dd in so:
    ti = dd[0] + ti
    if ti <= dd[1]:
        continue
    else:
        print('No')
        exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import fractions

#inp = [int(i) for i in input().split()]
inp = int(input())

task = []
for e in range(inp):
    task.append([int(i) for i in input().split()])

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

    ti = 0
    for dd in so:
        ti = dd[0] + ti
        if ti <= dd[1]:
            continue
        else:
            print('No')
            exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math

N = int(input())

#memo = [0 for _ in range(int(2*1e5)+1)]
memo = [0 for _ in range(2*int(1e9)+100)]

for _ in range(N):
	A,B = [int(s) for s in input().split(' ')]
	memo[B] += A

s = 0
flg = True
for i in range(len(memo)):
	s += memo[i]
	if s > i:
		flg = False
		break
if flg:
	print('Yes')
else:
	print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = []
B = []
C = []
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append(a)
    B.append(b)
    C.append(i)

def val(x):
    return B[x]

def merge(la,lb):
    ans = []
    while(len(la)>0 and len(lb)>0):
        if val(la[0]) < val(lb[0]):
            ans.append(la[0])
            la = la[1:]
        else:
            ans.append(lb[0])
            lb = lb[1:]
    for i in range(len(la)):
        ans.append(la[i])
    for i in range(len(lb)):
        ans.append(lb[i])
    return ans

def mergeSort(x):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d])
    right = mergeSort(x[d:])
    return merge(left,right)

C = mergeSort(C)

ans = "Yes"
t = 0
for i in range(N):
    t += A[C[i]]
    if t > B[C[i]]:
        ans = "No"

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a=[]
b=[]
for i in range(n):
    aa,bb = map(int,input().split())
    a.append(aa)
    b.append(bb)
sum = 0
for i in range(n):
    bb=b.index(min(b))
    bbuf = b.pop(bb)
    sum += a[bb]
    a.pop(bb)
    if sum>bbuf:
        print("No")
        exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    c = 0
    for j in range(i):
        if B[j] > b:
            c = j
            break
        c = i
    A.insert(c,a)
    B.insert(c,b)
found = True
SUM = 0
for i in range(N):
    SUM = SUM + A[i]
    if B[i] < SUM:
        found = False
if found:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    A = np.array(A)
    B = np.array(B)
    index = np.argsort(B)
    A_sorted = A[index]
    B_sorted = B[index]
    for i in range(N):
        sum_val = sum(A_sorted[:i+1])
        if sum_val > B_sorted[i]:
            print("No")
            return
    print("Yes")
    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
r=[]
for i in range(n):
    a,b=map(int,input().split())
    r.append(a)
    l.append(b)
r.sort()
l.sort()
c=0
for i in range(n):
    if sum(r[0:i+1])<=l[i]:
        c+=1 
if c==n:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

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

    time = 0
    while (len(AB) > 0):
        flag = True
        a, b = AB[0]
        if time + a <= b:
            time += a
            AB.pop(0)
            flag = False
        if flag:
            break
    if len(AB) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

time = 0
while (len(AB) > 0):
    flag = True
    if time + AB[0][0] <= AB[0][1]:
        time += AB[0][0]
        AB.pop(0)
        flag = False
    if flag:
        break
if len(AB) == 0:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lsta = []
lstb = []
for i in range(n):
  a,b = map(int, input().split())
  lsta.append(a)
  lstb.append(b)
jikan = 0
omg = False
for i in range(n):
  p = lstb.index(min(lstb))
  jikan += lsta[p]
  if jikan > lstb[p]:
    omg = True
    break
  lsta.pop(p)
  lstb.pop(p)
if omg == False:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

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

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

time = 0
while (len(AB) > 0):
    flag = True
    for i in range(len(AB)):
        if time + AB[i][0] <= AB[i][1]:
            time += AB[i][0]
            AB.pop(i)
            flag = False
            break
    if flag:
        break

if len(AB) == 0:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Limit = dict()
    for i in range(N):
        A, B = map(int, input().split())
        New = not B in Limit.keys()
        Limit[B] = Limit.get(B,0) + A
        if Limit[B] > B:
            return 'No'
        else:
            tk = 0
            for k in Limit.keys():
                if New and k < B:
                    tk = max(tk, k)

                if k > B:
                    Limit[k] += A
                    if Limit[k] > k:
                        return 'No'
            Limit[B] += Limit.get(tk,0)
            if Limit[B] > B:
                return 'No'

    return 'Yes'

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, exit

N = int(stdin.readline().rstrip())
work = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

work.sort(key=lambda x: x[1])
time = 0
for k in range(N):
    if time + work[0][0] > work[0][1]:
        print('No')
        exit()
    time += work.pop(0)[0]
print('Yes')

Submission status: Time Limit Exceeded

Solution code:


N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

while jobs:
    job = jobs.pop(0)
    time += job[0]
    if(time > job[1]):
        result = "No"
        break

print(result)

Submission status: Time Limit Exceeded

Solution code:


N = int(input())
jobs = []
for i in range(N):
    jobs.append(list(map(int, input().split())))
           
time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

while jobs:
    job = jobs.pop(0)
    time += job[0]
    if(time > job[1]):
        result = "No"


print(result)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
task_time = {}
task_limit = {}
for i in range(1,n+1):
    a,b = map(int,input().split())
    task_time[i] = a
    task_limit[i] = b

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

time = 0
for i in task_limit_sorted:
    time += task_time[i[0]]
    if task_limit[i[0]] < time:
        print ("No")
        exit ()

print ("Yes")

Submission status: Accepted

Solution code:
N = int(input())
Dic = dict()
for i in range(N):
    A,B = map(int,input().split())
    if B not in Dic:
        Dic[B] = A
    else:
        Dic[B] += A
Deadlines = sorted(Dic)
Time = 0
for Deadline in Deadlines:
    if Time+Dic[Deadline] <= Deadline:
        Time += Dic[Deadline]
    else:
        Ans = 'No'
try:
    if Ans =='No':
        print(Ans)
except:
    print('Yes')

Submission status: Accepted

Solution code:
N=int(input())
task=[tuple(map(int,input().split())) for _ in [0]*N]
task.sort(key=lambda x:x[1])
time=0
flg=True
for a,b in task:
    time+=a
    if b<time:
        flg=False
print(['No','Yes'][flg])

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    AB = [LI() for _ in range(N)]
    AB.sort(key=lambda x: x[1])

    ans = 'Yes'
    t = 0
    limit = 0
    for A, B in AB:
        limit = B
        t += A
        if t > limit:
            ans = 'No'
            break

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

	tasks.sort()

	t = 0
	for task in tasks:
		t += task[1]
		if t > task[0]:
			return False
	return True

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 12:27:12 2020

@author: liang
"""

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
task_list=[]
for i in range(n):
    task_list.append([int(x) for x in input().split()])
import operator
task_list.sort(key=operator.itemgetter(1))
time_now=0
for i in range(n):
    time_now+=task_list[i][0]
    if time_now>task_list[i][1]:
        print("No")
        exit()
    
print("Yes")

Submission status: Accepted

Solution code:
def abc131d_megalomania():
    n = int(input())
    d = []
    for _ in range(n):
        d.append(list(map(int, input().split())))
    d.sort(key=lambda x: x[1])
    t = 0
    for item in d:
        t += item[0]
        if t > item[1]:
            print('No')
            return
    print('Yes')
abc131d_megalomania()

Submission status: Accepted

Solution code:
N=int(input())
BA=[]
for _ in range(N):
    A,B=map(int,input().split())
    BA.append([B,A])
BA.sort()
T=0
for i in range(N):
    T+=BA[i][1]
    if T>BA[i][0]:
        print("No")
        break;
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
AB = [tuple(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[1])
cnt = 0
for a,b in AB:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
ab = [na() for _ in range(n)]
ab.sort(key=itemgetter(1, 0))
now = 0
ans = 'Yes'
for i in range(n):
    a, b = ab[i]
    now += a
    if now > b:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

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

    ba_lst = [0] * n
    for i in range(n):
        a = ab_lst[i][0]
        b = ab_lst[i][1]
        ba = [b, a]
        ba_lst[i] = ba
    ba_lst.sort()

    lst = []
    b = ba_lst[0][0]
    a = ba_lst[0][1]
    for i in range(n):
        b_tmp = ba_lst[i][0]
        a_tmp = ba_lst[i][1]

        if b == b_tmp:
            if i != 0:
                a += a_tmp
            if i == n - 1:
                lst.append([b, a])

        else:
            lst.append([b, a])
            b = b_tmp
            a = a_tmp

    if len(lst) > 1:
        if ba_lst[-1][0] != ba_lst[-2][0]:
            lst.append([ba_lst[-1][0], ba_lst[-1][1]])


    accumulate = 0
    flag = True
    for i in range(len(lst)):
        accumulate += lst[i][1]
        if accumulate > lst[i][0]:
            flag = False
            break

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    l = [i_list() for i in range(n)]
    l = sorted(l, key= lambda x: x[1])

    trial = 0
    for i,k in l:
        trial += i
        if trial > k:
            print("No")
            exit()
    print("Yes")


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    t = 0
    for a, b in sorted(AB, key=lambda x: x[1]):
        t += a
        if t > b:
            print('No')
            exit()
    print('Yes')


if __name__ == '__main__':
    main()

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])
a = [0] * n
a[0] = work[0][0]
for i in range(1,n):
    a[i] = a[i-1] + work[i][0]
ans = 'Yes'
for j in range(n):
    if a[j] > work[j][1]:
        ans = 'No'
        break
print(ans)

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 131
# D - Megalomania

import numpy as np


N=int(input())
ls=[]
for _ in range(N):
    p=list(map(int,input().split()))
    ls.append(p)

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

time=0

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

print("Yes")

Submission status: Accepted

Solution code:
from operator import *
N = int(input())
AB = [list(map(int,input().split())) for n in range(N)]
AB = sorted(AB,key=itemgetter(1))
ans = "Yes"
T = 0

for a,b in AB:
  T+=a
  if b<T:
    ans = "No"

print(ans)

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:
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
y = []
y = sorted(x, key = lambda x:x[1])
a = 0
for i in y:
    a += i[0]
    if a > i[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
Row = int(input())
List = []
for i in range (Row):
  List.append(list(map(int, input().split())))
List = sorted(List, key=lambda x: x[1])  #[1]に注目してソート
res = 0
flag = True
for i in range(Row):
  res += List[i][0]
  if res > List[i][1]:
    flag = False
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    adic = dict()
    bdic = dict()

    for i in range(n):
        a, b = map(int, input().split())
        adic[i+1] = a
        bdic[i+1] = b
    
    bdic2 = sorted(bdic.items(),key = lambda x:x[1])
    time = 0

    for dic in bdic2:
        shigoto = dic[0]
        time += adic[shigoto]
        if time > dic[1]:
            print("No")
            exit()
    
    print('Yes')





if __name__ == "__main__":
    main()

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])
w = 0
for x,y in L:
    w += x
    if w > y:
        print('No')
        exit()
print('Yes')

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])
w = 0
for i in range(N):
    x,y = L[i]
    w += x
    if w > y:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
AB = []
for _ in range(N):
    a, b = mapint()
    AB.append((a, b))
AB.sort(key=lambda x:x[1])
now = 0
for i in range(N):
    a, b = AB[i]
    if b-a<now:
        print('No')
        break
    now += a
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])
time = 0
ans = "Yes"
for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
        ans = "No"
        break
print(ans)

Submission status: Accepted

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

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

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

print("Yes")

Submission status: Accepted

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

AB = sorted(AB, key=lambda x: x[1])
#print(AB)
total = 0
flag = 1
for i in range(N):
  total += AB[i][0]
  if total > AB[i][1]:
    flag = 0
    break
if flag == 1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n = int(input())
arr = {}
for i in range(n):
  a,b= map(int, input().split( ))
  if b in arr:
    arr[b] += a
  else:
    arr[b] = a
time = 0
arrs = sorted(arr.items(), key=lambda x:x[0])
for lin in arrs:
  time += lin[1]
  if lin[0] < time:
    print('No')
    exit()
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.sort()
t=0
for i in range(n):
  t+=ba[i][1]
  if t<=ba[i][0]:
    continue
  else:
    print('No')
    exit()
print('Yes')

Submission status: Accepted

Solution code:
import pprint
n = int(input())
a = [[0]*2 for i in range(n)]
memo = 0 
ahozon = 0
for i in range(n):
  a[i][0],a[i][1]=map(int,input().split())
a.sort(key=lambda x: x[1])
for j in range(n):
  if(memo<=1):
    if(a[j][1]-a[j][0]-ahozon>=0):
      ahozon+=a[j][0]
    else:
      memo +=1
if(memo>=1):
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
work = []
for _ in range(N):
    a,b = mint()
    work.append([a,b])
work.sort(key=lambda x:x[1])
t = 0
ans = True
for a,b in work:
    if t+a>b:
        ans = False
        break
    t += a
judge(ans)

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],x[0]))
cur = 0
for a,b in L:
    if cur +a >b:
        print('No');exit()
    cur += a
print('Yes')

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	tasks = []
	for i in range(N):
		A, B = [int(x) for x in input().split(" ")]
		tasks.append({
			"time" : A,
			"deadline" : B
		})
	tasks.sort(key=lambda task: task["deadline"])
	tot = 0
	in_time = "Yes"
	for i in range(len(tasks)):
		t = tasks[i]["time"]
		d = tasks[i]["deadline"]
		tot += t
		if tot > d:
			in_time = "No"
			break
	print(in_time)

main()

Submission status: Accepted

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

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

n = 0
d = 0
f = 0
for i in range(N):
    n += t[i][0]
    if n > t[i][1]:
        f = 1
        break

if f == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
tasks = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    tasks.append([B, A])
tasks.sort()

ok = True
S = 0
for i in range(N):
    B, A = tasks[i][0], tasks[i][1]
    S += A
    if S > B:
        ok = False
        break

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

# D - Megalomania
N = int(input())
jobs = []

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

# 締め切り時刻の順にソート
jobs.sort(key=lambda x:x[1])

time = 0

for i in range(N):
  time += jobs[i][0]

  if time > jobs[i][1]:
    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])
total=0
for i in range(N):
    total+=AB[i][0]
    if total<=AB[i][1]:
        continue
    else:
        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])

hours = 0

ans = "Yes"
for pair in a:
    hours += pair[0]
    deadline = pair[1]


    if hours > deadline:
        ans = "No"
        break

print(ans)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, ABs):
    ABs.sort(key=lambda x: x[1])
    time = 0
    ans = 'Yes'
    for A, B in ABs:
        time += A
        if time > B:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    ABs = [[int(i) for i in input().split()] for _ in range(N)]
    # Bs = [int(i) for i in input().split()]
    solve(N, ABs)

Submission status: Accepted

Solution code:
N=int(input())
a=list()
for _ in range(N):
  A,B=map(int,input().split())
  a.append((B,A))
a.sort()
t=0
for i in range(N):
  t+=a[i][1]
  if t>a[i][0]:
    print("No")
    exit()
print("Yes")

Submission status: Accepted

Solution code:
# 52 D - Megalomania
N = int(input())
work = []
for _ in range(N):
    a,b = map(int,input().split())
    work.append((a,b))

# 締め切りが早い順にソート
work = sorted(work,key = lambda x:x[1],reverse = False)

result = 'Yes'
t = 0
for i,j in work:
    t += i
    if t>j:
        result = 'No'
        break
print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D
# CreatedDate:  2020-09-03 21:15:23 +0900
# LastModified: 2020-09-03 21:29:19 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    S = []
    for _ in range(n):
        S.append(list(map(int, input().split())))
    S.sort(key=lambda x:x[1])
    current_time = 0
    for s in S:
        current_time += s[0]
        if current_time <= s[1]:
            pass
        else:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
a, b = zip(*ab)
a = list(a)
b = list(b)
a = list(accumulate(a))
for i, j in zip(a, b):
    if i > j:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
import heapq

def solve():
    N = int(input())
    que = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(que, (b, a))
    now = 0
    while que:
        b, a = heapq.heappop(que)
        now += a
        if now > b:
            return False
    return True

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

Submission status: Accepted

Solution code:
import heapq

def solve():
    N = int(input())
    que = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(que, (-b, a))
    now = 10 ** 10
    while que:
        b, a = heapq.heappop(que)
        b = -b
        if now > b:
            now = b
        now -= a
        if now < 0:
            return False
    return True

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

Submission status: Accepted

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

Submission status: Accepted

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

tasks = sorted(tasks, key=lambda x: x[1])
time = 0
for task in tasks:
    time += task[0]
    if time > task[1]:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

sorted_AB = sorted(AB, key=lambda x:(x[1], -x[0]))
worked = 0
for ab in sorted_AB:
  worked += ab[0]
  if worked > ab[1]:
    print('No')
    exit(0)

print('Yes')

Submission status: Accepted

Solution code:
n = int(input())
tasks = [[0,0] for _ in range(n)]
for i in range(n):
  a, b = map(int, input().split())
  tasks[i][0] = a  # 所要時間
  tasks[i][1] = b  # 締め切り
tasks.sort(key=lambda t: t[1])
t = 0

for i in range(n):
  if t + tasks[i][0] > tasks[i][1]:
    print('No')
    exit()
  t += tasks[i][0]
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")
        exit()

print("Yes")