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())
T = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    T.append((a, b))
T = sorted(T, key=lambda x: x[1])[::-1]
d = [0] * n
d[0] = T[-1][0]
for i in range(n-1):
    d[i + 1] = d[i] + T[::-1][i + 1][0]
d = d[::-1]

f = 0
for i, (a, b) in enumerate(T):
    if b < d[i]:
        f = 1
        break
if f == 0:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
A = [0] * N
B = [0] * N

for _ in range(N):
    A[_], B[_] = map(int, input().split())
    if sum(A) > max(B):
        print("No")
        sys.exit()

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
def main():
    input = sys.stdin.readline
    N = int(input())
    A = deque()
    B = deque()
    cnt = 0 
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        cnt += sum(A) <= max(B)

    if cnt == N:
        print("Yes")

    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
A = deque()
B = deque()
Flg = deque() 
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    Flg.append(sum(A) <= max(B))

fig = all(Flg)
if fig:
    print("Yes")

else:
    print("No")

Submission status: Time Limit Exceeded

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

def my_sort(L, p, q):
    C = [[i, -1] for i in range(q - p + 1)]
    if p < q:
        mid = (p + q) // 2
        A = my_sort(L, p, mid)
        B = my_sort(L, mid + 1, q)
        i = 0
        j = 0
        k = 0
        while k < q - p + 1:
            if i >= mid - p + 1:
                C[k] = B[j]
                j += 1
            elif j >= q - mid:
                C[k] = A[i]
                i += 1
            else:
                if A[i][1] <= B[j][1]:
                    C[k] = A[i]
                    i += 1
                else:
                    C[k] = B[j]
                    j += 1
            k += 1
        return C
    else:
        return [L[p]]

n = int(input())
task = []
time_total = [0 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task = my_sort(task, 0, n - 1)
time_total[0] = task[0][0]
for i in range(n - 1):
    time_total[i + 1] = time_total[i] + task[i + 1][0]
while i < n:
    if time_total[i] > task[i][1]:
        print("No")
        sys.exit()
    i += 1
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from sys import exit

def my_sort(L, p, q):
    C = [[i, -1] for i in range(q - p + 1)]
    if p < q:
        mid = (p + q) // 2
        A = my_sort(L, p, mid)
        B = my_sort(L, mid + 1, q)
        i = 0
        j = 0
        k = 0
        while k < q - p + 1:
            if i >= mid - p + 1:
                C[k] = B[j]
                j += 1
            elif j >= q - mid:
                C[k] = A[i]
                i += 1
            else:
                if A[i][1] <= B[j][1]:
                    C[k] = A[i]
                    i += 1
                else:
                    C[k] = B[j]
                    j += 1
            k += 1
        return C
    else:
        return [L[p]]


n = int(input())
task = []
time_total = [0 for i in range(n)]
for i in range(n):
    task.append([int(i) for i in input().split()])
task = my_sort(task, 0, n - 1)
time_total[0] = task[0][0]
for i in range(n - 1):
    time_total[i + 1] = time_total[i] + task[i + 1][0]
while i < n:
    if time_total[i] > task[i][1]:
        print("No")
        exit()
    i += 1
print("Yes")

Submission status: Time Limit Exceeded

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

AB=sorted(AB, key=lambda val:val[1])
task=[]
for ab in AB:
    for _ in range(ab[0]):
        task.append(ab[1])
#print(AB)
#print(task)

for i in range(len(task)):
    if i+1>task[i]:
        print('No')
        break
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline())
A = [None]*N
B = [None]*N
for i in range(N):
    A[i], B[i] = map(int, stdin.readline().split())

now = 0
for i in range(N):
    job = B.index(min(B))
    now += A[job]
    deadline = B[job]
    B[job] = 10000000000
    if now > deadline:
        print("No")
        quit()
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline())
A = [None]*N
B = [None]*N
for i in range(N):
    A[i], B[i] = map(int, stdin.readline().split())

now = 0

for i in range(N):
    job = B.index(min(B))
    now += A.pop(job)
    deadline = B.pop(job)
    if now > deadline:
        print("No")
        quit()
else:
    print("Yes")

Submission status: Time Limit Exceeded

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

now = 0

for i in range(N):
    job = B.index(min(B))
    now += A.pop(job)
    deadline = B.pop(job)
    if now > deadline:
        print("No")
        quit()
else:
    print("Yes")

Submission status: Time Limit Exceeded

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

for i in range(n):
  suma=sum(a)
  maxb=max(b)
  if suma<=maxb:
    index=b.index(maxb)
    del a[index]
    del b[index]
  else:
    print('No')
    exit()
print('Yes')

Submission status: Time Limit Exceeded

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

for i in range(n):
  if sum(a)<=max(b):
    index=b.index(max(b))
    del a[index]
    del b[index]
  else:
    print('No')
    exit()
print('Yes')

Submission status: Time Limit Exceeded

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


def main():
    AB = []
    n = int(input())
    for i in range(n):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB = sorted(AB, key=lambda x: (x[1], -x[0]))
    time = 0
    while AB:
        span, dead = AB.pop(0)
        time += span
        if time > dead:
            print('No')
            return
    print('Yes')
    return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
    tasks = [[0] for _ in range(max(B) + 1)]
    for i in range(N):
        tasks[B[i]].append(A[i])
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0:
            continue
        time += sum(task)
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_A=[]
list_B=[]
list_AB=[]
for i in range(N):
	A, B = map(int,input().split())
	list_A.append(A)
	list_B.append(B)
	list_AB.append([list_A[i],list_B[i]])
sort_AB =sorted(list_AB, key=lambda x: x[1])
u=[]
def _judge_(k):
	for j in range(N-1):
		if k[j][0]>k[j][1]:
			return print("No")
		else:
			u.append(k[j][0])
			if sum(u)+k[j+1][0]>k[j+1][1]:
				return print("No")
	return print("Yes")
if N == 1:
	if A>B:
		print("No")
	else:
		print("Yes")
else:
	_judge_(sort_AB)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []
B = []
for i in range(N):
    a,b=map(int, input().split()) 
    A.append(a)
    B.append(b)
    tasks = dict(zip(range(N),B))

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

sum = 0
flg = False

for k, v in sorted_tasks:
    sum += A[k]
    if (sum > v):
        flg = True
        break

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
#これを加える！！！！
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

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

ans = 'Yes'
sorted_works = sorted(works, key=lambda x: x[1], reverse=True)
max_deadline = sorted_works[0][1]
# print('max_deadline', max_deadline)
h = []
deadline_i = 0
work_day = max_deadline # 作業日
# 締め切り最終日から0日に向かってループ
for d in range(max_deadline, -1, -1):
  # その日が締め切りの作業時間を優先度キューに追加
  for i in range(deadline_i, n):
    work_time, deadline = sorted_works[i]
    if deadline == d:
      _heappush_max(h, work_time)
      deadline_i += 1
    else:
      break
  # 作業ができない日であれば、次のループへ
  if d > work_day:
    continue
  
  # 作業ができる日
  
  # 作業がなければ次のループへ
  if len(h) == 0:
    continue
  
  
  # その日に終了しても良い作業の中で時間が最長の作業時間を取得
  max_work_time = _heappop_max(h)
  # 次の作業日を設定
  work_day = d - max_work_time
  
  # 0日より前になる = 作業量が多いので実行不可
  if work_day < 0:
    ans = 'No'
  
  

print(ans)
# print(works)
# print(sorted_works)

Submission status: Time Limit Exceeded

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

cond = True
cnt = 0
tmp = 0
for i in range(N):
	c,d = job.pop(0)
	cnt += (d - tmp)
	cnt -= c
	if cnt < 0:
		cond = False
		break
	tmp = d

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

t=0
flag=True
for _ in range(n):
  i=b.index(min(b))
  j=a.pop(i)
  k=b.pop(i)
  if j>k-t:
    print('No')
    flag=False
    break
  else:
    t += j
if flag:
  print('Yes')

Submission status: Time Limit Exceeded

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

t=0
flag=True
for _ in range(n):
  i=b.index(min(b))
  if a[i]>b[i]-t:
    print('No')
    flag=False
    break
  else:
    t += a[i]
  del a[i]
  del b[i]
if flag:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
time=0

for i in range(N):
    M,L=(int(j) for j in input().split())
    A.append(M)
    B.append(L)


for i in range(N):
    index=B.index(min(B))
    if (time+A[index])>B[index]:
        print("No")
        break;
    elif time+sum(A)>max(B):
        print("No")
        break;
    else:
        time=time+A[index]
        del A[index]
        del B[index]
if not A:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
time=0

for i in range(N):
    M,L=(int(j) for j in input().split())
    A.append(M)
    B.append(L)

if sum(A)>max(B):
    print("No")
else:
    for i in range(N):
        index=B.index(min(B))
        if (time+A[index])>B[index]:
            print("No")
            break;
        else:
            time=time+A[index]
            del A[index]
            del B[index]
if not A:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
time=0

for i in range(N):
    M,L=(int(j) for j in input().split())
    A.append(M)
    B.append(L)

for i in range(N):
    index=B.index(min(B))
    if (time+A[index])>B[index]:
        print("No")
        break;
    else:
        time=time+A[index]
        del A[index]
        del B[index]
if not A:
    print("Yes")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
import copy

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

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

t = 0
b2 = copy.deepcopy(b)
heapq.heapify(b2)

for i in range(n):
	minimum = heapq.heappop(b2)
	index = b.index(minimum)
	t += a[index]
	b[index] = -1
	if t > minimum:
		flag = False
		break

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ab=[list(map(int,input().split()))]
b=[ab[0]]
answer=1
for i in range(n-1):
    k=list(map(int,input().split()))#kを今からbの値でソートします
    d=0#何番目に入れるのが最適化を探すための代数です。
    while  d<=i and k[1]<=ab[d][1]:
        d+=1
    ab.insert(d,k) 
    b.insert(d,k)
#print(ab)
#print(b)
k=0
for t in range(n):
    k+=ab[n-1-t][0]
    #print([k,answer])
    if k>ab[n-1-t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

n = int(input())
a = []
res = ('Yes')
for i in range(n):
    a.append(list(map(int,input().split())))

a.sort(key=itemgetter(1))
for i in range(0,n):
    suma = 0
    for j in range(0,i+1):
        suma += a[j][0]
    if suma > a[i][1]:
        res = ('No')
        break


print(res)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
from itertools import accumulate
from operator import add


def solve(string):
    n, *ab = map(int, string.split())
    ab = reduce(add, sorted(zip(*[iter(ab)] * 2), key=lambda x: x[1]))
    return "Yes" if all([a <= b for a, b, in zip(accumulate(ab[::2]), ab[1::2])]) else "No"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))

Submission status: Time Limit Exceeded

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

for i in range(0,n):
    if lb[i] < sum(la[:i+1]):
        c = 1
        break
    else:
        continue
if c == 0:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
a=[]
b=[]
xa=[]
xb=[]
for i in range (0,N):
    c,d=(int(x) for x in input().split(" "))
    xa.append(c)
    xb.append(d)
     
z=np.argsort(xb)

for i in range (0,N):
    a.append(xa[z[i]])
    b.append(xb[z[i]])

def sum_a(i):
    e=0
    for k in range (0,i+1):
        e+=a[k]
    return e
def check(i,a,b):
    if b[i]>=sum_a(i):
        return True
    else:
        return False
def final_check(a,b,N):
    for i in range (0,N):
        if check(i,a,b)==False:
            return "No"
    return "Yes"
print (final_check(a,b,N))

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N = int(input())
    jobs = [tuple(map(int, input().split())) for _ in range(N)]
    jobs.sort(key=lambda x: x[1])

    cur_time = 0
    while jobs:
        job = jobs.pop(0)
        if job[1] < cur_time + job[0]:
            print("No")
            return 0
        else:
            cur_time += job[0]
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#りゅうせいの解答3
N = int(input())
task_list = [list(map(int, input().split())) for i in range(N)]

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

for j in range(N):
    x = task_list.pop(0)
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答2 正解
# N = int(input())
# task_list = [list(map(int, input().split())) for i in range(N)]
#
# task_list.sort(key=lambda task_list: task_list[1])
# time = 0
# flag = True
#
# for i in range(N):
#     x = task_list[i]
#     time += x[0]
#     if time > x[1]:
#         flag = False
#         break
#
# if flag:
#     print("Yes")
#
# else:
#     print("No")




#りゅうせいの解答1　実行時エラー(exit(1)が原因）、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#りゅうせいの解答3
N = int(input())
task_list = [list(map(int, input().split())) for i in range(N)]

task_list.sort(key=lambda task_list: task_list[1])
time = 0
flag = True

while(len(task_list)):
    x = task_list.pop(0)
    time += x[0]
    if time > x[1]:
        flag = False
        break

if flag:
    print("Yes")

else:
    print("No")




#りゅうせいの解答2 正解
# N = int(input())
# task_list = [list(map(int, input().split())) for i in range(N)]
#
# task_list.sort(key=lambda task_list: task_list[1])
# time = 0
# flag = True
#
# for i in range(N):
#     x = task_list[i]
#     time += x[0]
#     if time > x[1]:
#         flag = False
#         break
#
# if flag:
#     print("Yes")
#
# else:
#     print("No")




#りゅうせいの解答1　実行時エラー、実行時間超過
# N = int(input())
# task_list = [list(map(int,input().split())) for i in range(N)]
#
# task_list.sort(key= lambda task_list: task_list[1])
# time = 0
#
# while(len(task_list)):
#     x = task_list.pop(0)
#     time += x[0]
#     if time > x[1]:
#         print("No")
#         exit(1)
#
#     else:
#         continue
#
# print("Yes")

Submission status: Time Limit Exceeded

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):
    (d, c) = DeadlineCost.pop(0)

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

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
time = [0]*n
dl = [0]*n
for i in range(n):
    time[i], dl[i] = map(int, input().split())
count = 0
while len(dl):
    index = dl.index(min(dl))
    count += time[index]
    if count > dl[index]:
        print("No")
        exit()
    dl.pop(index)
    time.pop(index)
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#ABC131d 配列で考えたほうがいいかも　スタート時刻の配列と締め切りの配列

import numpy as np

n=int(input())
alist=[0 for i in range(n)]
blist=[0 for i in range(n)]
answer="Yes"

for i in range(n):
	alist[i],blist[i]=map(int,input().split())

ablist=np.array([[0,0] for i in range(n)])

for i in range(n):
	ablist[i][0]=alist[i]
	ablist[i][1]=blist[i]

ablist2=ablist[np.argsort(ablist[:,1])]
#print(ablist2)

for i in range(n):
	if sum(ablist2[0:i+1])[0] > ablist2[i][1]:
		answer="No"
#		print(sum(ablist2[0:1+1])[0])
#		print(ablist2[i][1])
#		print(i)
print(answer)

Submission status: Time Limit Exceeded

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

N = int(input())

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

# sort
for i in range(len(list)):
    Ai, Bi = list[i]
    minIndex = None
    min = Bi
    for j in range(i+1,len(list)):
        Aj, Bj = list[j]

        if min > Bj:
            min = Bj
            minIndex = j

    if minIndex != None:
        list[i],list[minIndex] = list[minIndex],list[i]

#check
time = 0
result = True
for i in list:
    A, B = i
    time += A

    #print("work[{0}({1},{2})] time:{3}".format(i,A,B,time))

    if time > B:
        result = False
        break

message = "Yes" if result else "No"
print(message)

Submission status: Time Limit Exceeded

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

N = int(input())

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

# sort
for i in range(len(list)):
    for j in range(i+1,len(list)):
        Ai, Bi = list[i]
        Aj, Bj = list[j]

#        pr_i = Bi - Ai
#        pr_j = Bj - Aj

        if Bi > Bj:
            list[i], list[j] = list[j], list[i]

#check
time = 0
result = True
for i in list:
    A, B = i
    time += A

#    print("work[{0}({1},{2})] time:{3}".format(i,A,B,time))

    if time > B:
        result = False
        break

message = "Yes" if result else "No"
print(message)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter
n=int(input())
d=[]
judge=True
bag=[]
for i in range(n):
    a,b=map(int,input().split())
    d.append([a,b])
d.sort(key=itemgetter(1))
        
for j in range(len(d)):
    bag.append(d[j][0])
    if sum(bag)>d[j][1]:
        judge=False
else:
    if judge==True:
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AB = []
for i in range(N):
  AB_1,AB_2 = map(int,input().split())
  AB.append([AB_1,AB_2])
AB.sort(key=lambda AB: AB[0],reverse=True)
AB.sort(key=lambda AB: AB[1])
time = 0
count = 0
while count < N:
  for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
      ans = "No"
      break

Submission status: Time Limit Exceeded

Solution code:
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
    return a


N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
ab = bSort(ab)
for i in range(N):
    for j in range(i, N):
        ab[j][1] -= ab[i][0]
        if ab[j][1] < 0:
            print("No")
            exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[1])
for i in range(N):
    for j in range(i, N):
        ab[j][1] -= ab[i][0]
        if ab[j][1] < 0:
            print("No")
            exit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab, key=lambda x: x[1])
for i in range(N):
    for j in range(i, N):
        ab[j][1] -= ab[i][0]
        if ab[j][1] < 0:
            print("No")
            exit()
    ab = ab[:i] + sorted(ab[i:], key=lambda x: x[1])

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

n = int(input())
ab = [(0, 0) for _ in range(n)]

for i in range(n):
    ab[i] = tuple(map(int, input().split()))
    
def mergesort(ab, l, r):
    if r - l == 1:
        return [ab[l]]
    m = (l + r) // 2
    ab1 = mergesort(ab, l, m)
    ab2 = mergesort(ab, m, r)
    res = []
    i1, i2 = 0, 0
    while i1 < len(ab1) or i2 < len(ab2):
        if i1 == len(ab1):
            res.append(ab2[i2])
            i2 += 1
        elif i2 == len(ab2):
            res.append(ab1[i1])
            i1 += 1
        else:
            if ab1[i1][1] <= ab2[i2][1]:
                res.append(ab1[i1])
                i1 += 1
            else:
                res.append(ab2[i2])
                i2 += 1
    return res
    
sorted_ab = mergesort(ab, 0, n)

now = 0
flag = True
for task in sorted_ab:
    now += task[0]
    if now > task[1]:
        print('No')
        flag = False
        break

if flag:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = []
Bs = []
for _ in range(N):
  A, B = map(int, input().split())
  index = -1
  for i in range(len(Bs)):
    if Bs[i] > B:
      index = i
      break
  if index < 0:
    As.append(A)
    Bs.append(B)
  else:
    As.insert(index, A)
    Bs.insert(index, B)


time = 0
flg = True
for i in range(len(As)):
  time += As[i]
  if time > Bs[i]:
    flg = False
    break

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
import numpy as np
A=np.zeros(N)
B=np.zeros(N)
for i in range(0,N):
  A[i],B[i] = map(int,input().split())

BB=list(set(list(B)))
for b in BB:
  if np.sum(A[B<=b])>b:
    print('No')
    break
else:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
import numpy as np
A=np.zeros(N)
B=np.zeros(N)
for i in range(0,N):
  A[i],B[i] = map(int,input().split())

for b in B:
  if np.sum(A[B<=b])>b:
    print('No')
    break
else:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [None for _ in range(N)]
B = [None for _ in range(N)]
endflg = [0 for _ in range(N)]
for i in range(N):
  A[i],B[i] = map(int,input().split())
time = 0

limit = max(B) + 1

for i in range(N):
  Pb = B.index(min(B))
  if time + A[Pb] <= B[Pb]:
    endflg[Pb] = 1
    B[Pb] = limit
    time = time + A[Pb]
  else:
    break
    
if endflg == [1 for _ in range(N)]:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

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

now_time = 0
flag = True
for i in range(N):
  min_b = min(B)
  min_b_idx = B.index(min_b)
  now_time += A[min_b_idx]
  del B[min_b_idx]
  del A[min_b_idx]
  if now_time > min_b:
    flag = False
if flag:
  print('Yes')
else:
  print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A,B,C=[None]*N,[None]*N,dict()
for i in range(N):
  A[i],B[i] = [int(j) for j in input().split()]
  if not B[i] in C:
    C[B[i]] = []
  C[B[i]] += [[A[i],B[i]]]
C = sorted(C.items(), key=lambda C:C[0])
s=0
for k,v in C:
  for i in v:
    s+=i[0]
    if i[1]<s:
      print('No')
      exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
def insertionsort(a,A):
    flg=0
    if len(A)>0:
        for i in range(len(A)):
            if A[i][1]==a[1]:
                if A[i][0]>a[1]:
                    A=A[:i]+[a]+A[i:]
                else:
                    A=A[:i+1]+[a]+A[i+1:]
                flg=1
                break
            elif A[i][1]>a[1]:
                A=A[:i]+[a]+A[i:]
                flg=1
                break
    if flg==0:
        A.append(a)
    return A



if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work=insertionsort(W,work)
    
    result=work[0][0]
    i=0

    while result<=work[i][1]:
        i+=1
        if i<N:
            result+=work[i][0]
        else:
            break
    if i==N:
        print('Yes')
    else:
        print('No')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
#A = [a for a,b in AB]
#B = [b for a,b in AB]
#C = list(range(N))

def merge(la, lb, key):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if key(la[ia]) < key(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  return ans
    
def mergeSort(x, key):
    l = len(x)
    if l <= 1:
        return x
    d = l // 2 
    left = mergeSort(x[:d], key)
    right = mergeSort(x[d:], key)
    return merge(left,right, key)

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

ans = "Yes"
t = 0
for a,b in AB:
    t += a
    if t > b:
        ans = "No"

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
A = [a for a,b in AB]
B = [b for a,b in AB]
C = list(range(N))

def val(x):
  return B[x]

def merge(la, lb):
  na = len(la)
  nb = len(lb)
  ans = [None] * (na+nb)
  ia = 0
  ib = 0
  
  while ia<na and ib<nb:
    if val(la[ia]) < val(lb[ib]):
      ans[ia+ib] = la[ia]
      ia += 1
    else:
      ans[ia+ib] = lb[ib]
      ib += 1
      
  if ia<len(la):
    ans[ia+ib:] = la[ia:]
  if ib<len(lb):
    ans[ia+ib:] = lb[ib:]
  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:
import sys

N = int(input())
TASKS = []
for i in range(1, N+1):
    A,B = map(int, input().split())
    TASKS.append([A,B])

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

#print(TASKS)

time = 0

for i in range(1, N+1):
    task = TASKS.pop(0)
    a = task[0]
    b = task[1]
    time += a
    if time <= b:
        continue
    else:
        print("No")
        sys.exit()

print("Yes")