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

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort()
#print(DeadlineCost)


t = 0
for i in range(N):
    # .pop じゃなくて参照に変更するとどれぐらい速くなる？
    (d, c) = DeadlineCost[i]

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

B, A = zip(*sorted(zip(B, A)))

for i in range(N):
    ft += A[i]
    if ft > B[i]:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:

N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    # tupleじゃなくて array だとどれぐらい遅くなる？
    DeadlineCost.append([d, c])

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)


t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:

N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)

t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

Solution code:

N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)

t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

Submission status: Accepted

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

n = int(input().split()[0])
ab_list = []
is_ok = True

for _ in range(n):
    a, b = list(map(int, input().split()))
    ab_list.append((a, b))

ab_list = sorted(ab_list, key=lambda x: x[1])
now_t = 0
is_ok = True

for i, ab in enumerate(ab_list):
    a, b = ab
    s_deadline = b - a

    if now_t > s_deadline:
        # 現在時刻が、開始時刻のデッドラインを過ぎている
        is_ok = False
        break
    now_t += a

ans = 'Yes' if is_ok else 'No'
print(ans)

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

from operator import itemgetter as get

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)], key=get(1)
    )
    cur = 0
    for task, deadline in A:  # check all tasks greedily
        cur += task
        if cur > deadline:  # fail to finish a task within its deadline
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

from itertools import accumulate


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

from itertools import accumulate
from operator import itemgetter as get


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[1]
    )
    tasks = 0
    for task, deadline in A:
        tasks += task
        if tasks > deadline:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans = True
ti = 0
for i in arr:
    if ti + i[0] > i[1]:
        ans = False
        break
    ti += i[0]
if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

spend_time = 0
flg = True

for a,b in A_B:
  spend_time += a
  if spend_time > b:
    flg = False
    break
  else:
    continue

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

Submission status: Accepted

Solution code:
n = int(input())

totalDay = 0
cost = 0
ans = "Yes"

#{締め切り,必要な日数}
jobs = [ [0]*2 for _ in range(n)]
for i in range(n):
    s, t = map(int, input().split())
    jobs[i] = [t, s]
jobs.sort()
for i in range(n):
    totalDay += jobs[i][1]
    if totalDay <= jobs[i][0]:
        continue
    else:
        ans = "No"
        break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools as it

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

np_input = np.asarray(inputs)
np_input =np.hstack((np_input,list(it.accumulate(np_input[:,:1]))))

flg=False
for row in np_input:
    if row[1] < row[2]:
        flg=True
        break

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

Submission status: Accepted

Solution code:
n = int(input())
ab = []

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

def detect():
    t = 0
    for a, b in ab:
        if t + a > b:
            return "No"
        t += a
    return "Yes"

print(detect())

Submission status: Accepted

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)]
AB=sorted(AB,key=lambda x: x[1])
day = 0
Flag = True
for i in range(N):
    day += AB[i][0]
    #print(day, AB[i][1])
    if day > AB[i][1]:
        Flag = False
        break
if Flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

check = 0
tmp = 0
for i in range(N):
    tmp += l[i][0]
    if tmp > l[i][1]:
        check = 1

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

Submission status: Accepted

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

time = 0
for x,y in lst:
    time += x
    if time > y:
        print('No')
        exit()
else:
    print('Yes')

Submission status: Accepted

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

time = 0
for x,y in lst:
    time += x
    if time > y:
        print('No')
        break
else:
    print('Yes')

Submission status: Accepted

Solution code:
#coding utf-8
from operator import itemgetter
N=int(input())
AB=[[int(i) for i in input().split()+[0]] for i in range(N)]
C=[0 for i in range(N)]


AB.sort(key=itemgetter(1))
time=0
ans=0
for i in range(N):
  time+=AB[i][0]
  if time>AB[i][1]:
    ans=1
    break

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(1))
sum = 0
for a, b in AB:
    sum += a
    if sum > b:
        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])
now = 0
ret = "Yes"
for a, b in AB:
    now += a
    if b < now:
        ret = "No"
        break


print(ret)

Submission status: Accepted

Solution code:
N = int(input())
job_list = list()
for i in range(N):
    job_list.append(tuple(map(int, str(input()).split())))

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

time = 0
for i in range(N):
    time += job_list[i][0]
    if time > job_list[i][1]:
        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], x[0]))
tt = 0
for i in ab:
    tt += i[0]
    if tt > i[1]:
        print("No")
        exit()
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()

time=0
flag=True
for i in task:
    time-=i[1]
    if time>i[0]:
        flag=False
        break

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())

dct = defaultdict(list)

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

ans = 0
dct_list = sorted(dct.items())
for el in dct_list:
    ans += sum(el[1])
    if el[0] < ans:
        print("No")
        exit()
print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split())) for k in range(n)]
a.sort(key = lambda x: x[1])
worktime = 0
deadline = 0
for i in range(n):
    if worktime <= deadline:
        worktime += a[i][0]
        deadline = a[i][1]
        if worktime <= deadline and i == n-1:
            print('Yes')
        elif worktime > deadline and i == n-1:
            print('No')
        else:
            pass
    else:
         print('No')
         break

Submission status: Accepted

Solution code:
import numpy as np

n=int(input())
ablist=[[int(x) for x in input().split()] for _ in range(n)]

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

ruiseki=np.cumsum([item[0] for item in ablist])

if all([ruiseki[i]<=ablist[i][1] for i in range(n)]):
  print("Yes")
else:
  print("No")

Submission status: Accepted

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

time = 0
f = False

for i in range(N):
  time += AB[i][0]
  if time > AB[i][1]:
    f = True
    break
if f:
  print("No")
else:
  print("Yes")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#40 ABC131D
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
ab=sorted(ab,key=lambda x:x[1])
j=True
x=0
for a,b in ab:
	x+=a
	if x>b:
		j=False
		break
print("Yes" if j else "No")

Submission status: Accepted

Solution code:
from operator import itemgetter as ig
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
    N = int(input())
    AB = (tuple(map(int, input().split())) for _ in range(N))
    ab = sorted(AB, key=ig(1))
    sum_a = 0
    for a, b in ab:
        sum_a += a
        if b < sum_a:
            print("No")
            break
    else:
        print("Yes")

main()

Submission status: Accepted

Solution code:
class Task:
    count=0
    def __init__(self,time,deadline):
        Task.count+=1
        self.time=time
        self.deadline=deadline
        self.count=Task.count
    
    def __gt__(self,other):
        if self.deadline<other.deadline:
            return True
        if self.deadline==other.deadline:
            if self.time<other.time:
                return True
            if self.time==other.time:
                if self.count<other.count:
                    return True
        return False
    
    def __lt__(self,other):
        if self.deadline>other.deadline:
            return True
        if self.deadline==other.deadline:
            if self.time>other.time:
                return True
            if self.time==other.time:
                if self.count>other.count:
                    return True
        return False
    

tasklist=[]    
n=int(input())
for i in range(n):
    time,deadline=[int(j) for j in input().split()]
    task=Task(time,deadline)
    tasklist.append(task)
check=0
time=0
tasklist.sort()



while tasklist:
    task=tasklist.pop()
    if task.time+time>task.deadline:
        check+=1
        print("No")
        break
    else:
        time+=task.time
        
if check==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])

#経過時間
cnt_times = 0
for i in range(N):
    if cnt_times + AB[i][0] <= AB[i][1]:
        cnt_times += AB[i][0]
    else:
        print("No")
        exit()
        
print("Yes")

Submission status: Accepted

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

a.sort(key=lambda x:x[1])
time=0
over=0
for i in range(n):
    if time+a[i][0]>a[i][1]:
      over=1
      break
    else:
        time+=a[i][0]

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

Submission status: Accepted

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

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

now = 0
msg = 'Yes'
for task in tasklist:
    if now + task[0] > task[1]:
        msg = 'No'
        break
    else:
        now += task[0]

print( msg )

Submission status: Accepted

Solution code:
import heapq
n = int(input())
A = []
for _ in range(n):
    a, b = map(int, input().split())
    heapq.heappush(A, [b, a])
a_sum = 0
f = 1
for _ in range(n):
    b, a = heapq.heappop(A)
    a_sum += a
    if a_sum > b:
        f = 0
        break
print(["No", "Yes"][f])

Submission status: Accepted

Solution code:
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n=getint()
a=[getints() for _ in range(n)]
a=list(sorted(a,key=lambda s: s[1]))

now=0
ok=True
for i in range(n):
    now += a[i][0]
    if now > a[i][1]:
        ok = False

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

Submission status: Accepted

Solution code:
from operator import itemgetter
a = int(input())
l = []
for i in range(a):
    t,T = map(int,input().split())
    l.append((t,T))
l = sorted(l, key=itemgetter(1), reverse=False)
# print(l)
E = 0
S = 0 
s = 0
for i , j in l :
    E += abs(E-j)
    S += i
    if S>E:
        s=1 
def Y(a,t = 0):
    if a==t : print('YES')
    else : print('NO')
def y(a, t =0):
    if a==t : print('Yes')
    else : print('No')

y(s)

Submission status: Accepted

Solution code:
from operator import itemgetter


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

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

    acc = 0
    answer = 'Yes'
    for a, b in ab:
        acc += a
        if acc > b:
            answer = 'No'
            break

    print(answer)


main()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    ab = sorted(list(list(map(int, input().split())) for _ in range(n)), key=lambda x: x[1])
    total_time = 0
    for a, b in ab:
        total_time += a
        if b < total_time:
            return "No"
    return "Yes"


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

Submission status: Accepted

Solution code:
n=int(input())
m=[]
for i in range(n):
    [p,q]=[int(x) for x in input().split()]
    m.append([p,q])
m.sort(key=lambda x:x[1])
su=0
flag=True
for i in m:
    su+=i[0]
    if su>i[1]:
        flag=False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
N=int(input())
d=[]
for n in range(N):
    d.append(list(map(int,input().split())))
d_1=sorted(d,key=lambda d:d[1])
t=0
for n in range(N):
    t+=d_1[n][0]
    if t>d_1[n][1]:
        print("No")
        exit(0)
print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
A = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
  A[i][0],A[i][1]=map(int,input().split())
  

A = sorted(A, key=lambda x: x[1])
sum=0
for i in range(n):
  sum+=A[i][0]
  if sum>A[i][1]:
    print('No')
    break
  if i==n-1:
    print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

ok_time = 0
dame_time = 0

answer = "Yes"
for i in range(N):
    ok_time = C[i][1]
    dame_time += C[i][0]
    if dame_time > ok_time:
        answer = "No"
print(answer)

Submission status: Accepted

Solution code:
import sys

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

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

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

print("Yes")

Submission status: Accepted

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

Submission status: Accepted

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

flag = True
time = 0
for elem in sch:
    need, limit = elem
    time += need
    if time > limit:
        flag = False
        break

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

Submission status: Accepted

Solution code:
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])
t = 0
for job in jobs:
    a, b = job
    t += a
    if (t > b):
        print('No')
        exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC131 D
from operator import itemgetter as ig
N = int(input())
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
    A[i], B[i] = (int(_) for _ in input().split())
AB = sorted([(A[i], B[i])for i in range(N)], key = ig(1))
last = 0
ans = True
for i in range(N):
    last += AB[i][0]
    if last <= AB[i][1]:
        continue
    else:
        ans = False
        break
if ans:
    print("Yes")
else:
    print("No")

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])
T = 0
lim = 0
for i in range(n):
  T += ab[i][0]
  lim = ab[i][1]
  if T > lim:
    print("No")
    sys.exit()
print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
task = [list(map(int, input().split())) for i in range(n)]
# print(n)
# print(task)
import numpy as np
task = np.array(task)
# print(task[:,1])
# print(np.argsort(task[:,1]))
newtask = task[np.argsort(task[:,1])]
# print(newtask)
t = 0
for i in range(n):
    t += newtask[i,0]
    if t > newtask[i,1]:
        print("No")
        exit()
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])
t = 0

for i in range(n):
    if t+ab[i][0] > ab[i][1]: print("No"); sys.exit()
    else: t += ab[i][0]
else:
    print("Yes")

Submission status: Accepted

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

t_sort=sorted(t,key=lambda x: x[1])
for i in range(n):
    time+=t_sort[i][0]
    if time>t_sort[i][1]:
        print("No")
        break
    else:
        if i==(n-1):
            print("Yes")

Submission status: Accepted

Solution code:
# 締切が近い順に処理する（締め切り時間が同じならかける時間は関係ない）

n = int(input())

# こういう処理pythonでうまくやる方法ないのかな ...
hash = {}
for _ in range(n):
    a, b = map(int, input().split())
    if b in hash:
        hash[b].append(a)
    else:
        hash[b] = [a]
arr = []
for k, v in hash.items():
    arr.append([k, v])
arr = list(sorted(arr, key=lambda x: x[0]))

count = 0
for a in arr:
    for ai in a[1]:
        if count + ai > a[0]:
            print("No")
            exit()
        else:
            count += ai
print("Yes")

Submission status: Accepted

Solution code:
N = int(input())

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

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

t = 0
flg = True
for w in works:
    t += w[0]
    if t > w[1]:
        flg = False

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

Submission status: Accepted

Solution code:


N = int(input())
a_b = [[int(x) for x in input().split()] for i in range(N)]
sorted_tasks = sorted(a_b, key=lambda x: x[1])
current_time = 0
is_no = False
for task in sorted_tasks:
    current_time += task[0]
    if task[1] < current_time:
        is_no = True
        break

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

Submission status: Accepted

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

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

isYes = True
totalA = 0
for i in range(N):
    totalA += arr[i][0]
    if totalA > arr[i][1]:
        isYes = False

if isYes:
    print('Yes')
else:
    print('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")
    exit()
else:
  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])
a=0
for i,j in l:
  a+=i
  if a>j:
    print("No");exit()
print("Yes")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# 仕事を同時並行して進めることはできないし、順番によって必要時間がかかるわけではないから締め切りが近い順に貪欲？

n = int(input())

jobs = []

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

job_count = 0
pass_time = 0

for j in jobs:
    if pass_time + j[1] <= j[0]:
        job_count += 1
        pass_time += j[1]
    else:
        break

if job_count == n:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter

def main():
	n = int(input().strip())
	s = [[0] * 2 for _ in range(n)]
	for i in range(n):
		s[i][0], s[i][1] = map(int, input().strip().split())
	s2 = sorted(s, key=itemgetter(1))
	t = 0
	for item in s2:
		t += item[0]
		if t > item[1]:
			print('No')
			return
	print('Yes')

if __name__ == '__main__':
	main()

Submission status: Accepted

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

end = 0
for p,q in a:
    end += q
    if end > p:
        print('No')
        exit()
print('Yes')

Submission status: Accepted

Solution code:
import sys
from functools import cmp_to_key
n = int(input())
data = [[int(j) for j in input().split()] for i in range(n)]
t = 0
data.sort(key = cmp_to_key(lambda x, y: x[1] - y[1]))
for d in data:
  t += d[0]
  if t > d[1]:
    print('No')
    sys.exit()
print('Yes')

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    time[i] = [time[i][1],time[i][0]]

time.sort()

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

print(ans)

Submission status: Accepted

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

l.sort()

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

Submission status: Accepted

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

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

count = 0
can = True
for i in range(n):
    count = count + ab[i][0]
    if count > ab[i][1]:
        print("No")
        can = False
        break

if can:
    print("Yes")

Submission status: Accepted

Solution code:
N = int( input() )
n = []
for i in range(N):
	n.append(input().split())
	n[i][0] = int(n[i][0])
	n[i][1] = int(n[i][1])

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

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

Submission status: Accepted

Solution code:
#abc131d
import sys

n=int(raw_input())
ab=[]
for i in xrange(n):
 a,b=map(int,raw_input().split())
 ab.append([a,b])
ab=sorted(ab,key=lambda x:x[1])
acm=0
for i in xrange(n):
 acm+=ab[i][0]
 if acm>ab[i][1]:
  print 'No'
  sys.exit()
print 'Yes'

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

def main():
	n=int(input())
	l=[];t=0;flg=0
	for i in range(1,n+1,1):
		a,b=map(int,input().split())
		c=(b,a)
		l.append(c)
	l.sort()
	flag = True
	for x,y in l:
		t+=y
		if t>x:
			flag = False
	if flag:print("Yes")
	else:print("No")

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Submission status: Accepted

Solution code:
n = int(input())
l = [None] * n
for i in range(n):
  l[i] = list(map(int, input().split()))
l.sort(key=lambda x:x[1])
t = 0
for a, b in l:
  t += a
  if t > b:
    print('No')
    exit(0)
print('Yes')

Submission status: Accepted

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

s = 0
f = True
for i in range(n):
    s += ba[i][1]
    if ba[i][0] < s:
        f = False
        break
if f:
    print("Yes")
else:
    print("No")

Submission status: Accepted

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

inputs.sort(key=lambda x: x[1])
time = 0
for item in inputs:
    time += item[0]
    if time > item[1]:
        print('No')
        break
else:
    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])
time = 0
for w, t in l:
    time += w
    if t < time:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Accepted

Solution code:
n=int(input())
l=[];t=0;flg=0
for i in range(1,n+1,1):
    a,b=map(int,input().split())
    c=(b,a)
    l.append(c)
l.sort()
for x,y in l:
    t+=y
    if t>x:
        flg=1
if flg==0:print("Yes")
else:print("No")

Submission status: Accepted

Solution code:

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