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 = []
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 = []
    a,b=0,0
    while(len(la)>a and len(lb)>b):
        if val(la[a]) < val(lb[b]):
            ans.append(la[a])
            a+=1
        else:
            ans.append(lb[b])
            b+=1
    for i in range(a,len(la)):
        ans.append(la[i])
    for i in range(b,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())
L = [list(map(int,input().split())) for i in range(N)]

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

calc = 0
ans = "Yes"

while L :
    A,B = L.pop(0)
    calc += A
    if calc > B :
        ans = "No"
        break

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

#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 = sorted(B)

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

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)

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

    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())
l = []
s = 0
for i in range(n):
  a, b = map(int, input().split())
  s += a
  l.append((a, b))
  
l = sorted(l, key=lambda x: x[1], reverse=True)
for i in range(n):
  if s > l[0][1]:
    print("No")
    exit()
  else:
    a = l.pop(0)
    s -= a[0]
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append((a, b))
  
l = sorted(l, key=lambda x: x[1], reverse=True)
s = sum(j for j, _ in l)
for i in range(n):
  if s > l[0][1]:
    print("No")
    exit()
  else:
    a = l.pop(0)
    s -= a[0]
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N = int(input())

AB = np.zeros([2,N])

for i in range(N):
    AB[:,i] = list(map(int, input().split()))
    if AB[0,i] > AB[1,i]:
        print('No')
        sys.exit()

# 締切の近い順に並び替え
AB = AB[:,np.argsort(AB[1,:])]

time = 0
for i in range(0,N):
    time += AB[0,i]
    if AB[1,i] - time < 0:
        print('No')
        sys.exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

N = int(input())

AB = np.zeros([2,N])

for i in range(N):
    AB[:,i] = list(map(int, input().split()))
    if AB[0,i] > AB[1,i]:
        print('No')
        sys.exit()

# 締切の近い順に並び替え
AB = AB[:,np.argsort(AB[1,:])]

time = np.zeros(N)
time[0] = AB[0,0]

for i in range(1,N):
    time[i] = time[i-1] + AB[0,i]

if np.all(AB[1,:] - time >= 0 ) == True:
    print('Yes')
    sys.exit()

print('No')

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.empty((0,2),int)
for i in range(n):
    b = np.array([[int(i) for i in input().split()]])
    a = np.append(a,b,axis=0)
a = a[np.argsort(a[:, 1])]
ans = "Yes"
k = 0
for i in range(len(a)):
    k += a[i,0]
    if k > a[i,1]:
        ans = "No"
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re
import bisect

def main():
    #A, B, C, D = map(int, input().split())
    N = int(input())
    diff_list = []
    for i in range(N):
        A, B = map(int, input().split())
        bisect.insort_left(diff_list, (B, A))

    t = 0
    for i in range(N):
        B, A = diff_list[i]
        t += A
        if t > B:
            print("No")
            return

    print("Yes")

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.empty((0,2),int)
for i in range(n):
    b = np.array([[int(i) for i in input().split()]])
    a = np.append(a,b,axis=0)

a = a[np.argsort(a[:, 1])]

ans = "Yes"
for i in range(len(a)):
    if np.sum(a[0:i+1,0]) > a[i,1]:
        ans = "No"
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.empty((0,2),int)
for i in range(n):
    b = np.array([[int(i) for i in input().split()]])
    a = np.append(a,b,axis=0)

a = a[np.argsort(a[:, 1])]

ans = "Yes"
for i in range(len(a)):
    if sum(a[0:i+1,0]) > a[i,1]:
        ans = "No"
print(ans)

Submission status: Time Limit Exceeded

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

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]

left=z[1,0]
flag='Yes'
for i in range(N):
  if min(left,z[1,i])<z[0,i:].sum():
    flag='No'
    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
arr = [0] * N

for i in range(N):
    a, b = map(int, input().split())
    arr[i] = [a, b]
    
arr = sorted(arr, key=lambda x:x[1])
arr = np.array(arr)

ans = "Yes"
for i in range(len(arr)):
  if np.sum(arr[:i+1], axis=0)[0] > arr[i][1]:
    ans = "No"
    break
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tasks = [(0, 0)] * N
for i in range(N):
  A, B = [int(x) for x in input().split(' ')]
  tasks[i] = (A, B)
  
tasks.sort(key=lambda x: x[1])
T = 0
while len(tasks) > 0:
  t = tasks[0]
  T = T + t[0]
  d = t[1]
  if T > d:
    print("No")
    break
  tasks.pop(0)
  
if len(tasks) == 0:
  print("Yes")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sche = [[0,0] for i in range(N)]

for i in range(N):
    tmp_a, tmp_b = map(int, input().split())
    sche[i][0] = tmp_a
    sche[i][1] = tmp_b



def search_lms(N, sche, now):
    sub_time = 10000000000
    num = 0
    for i in range(len(sche)):
        if sub_time > sche[i][1]:
            sub_time = sche[i][1]
            num = i
    return num
        #差の最小値を見つける

now = 0
tmp = 0
for i in range(N):
    tmp = search_lms(N, sche, now)
    if now + sche[tmp][0] > sche[tmp][1]:
        print("No")
        exit()
    now += sche[tmp][0]
    sche.pop(tmp)

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
str = input()
N = int(str.split()[0])

A = []
B = []
for i in range(N) :
	str = input()
	A.append(int(str.split()[0]))
	B.append(int(str.split()[1]))
end = 0
en = 0
while (end == 0) :
	k = 0
	for i in range(len(A)) :
		k += A[i]
	s = 0
	t = 0
	a = -1
	for i in range(len(B)) :
		if (s < B[i]) :
			s = B[i]
			t = i
		if (s == B[i]) :
			if (a == -1) :
				a = A[i]
				t = i
			elif (a > A[i]) :
				a = A[i]
				t = i
	A.pop(t)
	B.pop(t)
	if (len(A) == 0) :
		if (k > s) :
			en = 1
		end = 1
	if (k > s) :
		en = 1
		end = 1

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
arr = [0] * N

for i in range(N):
    a, b = map(int, input().split())
    arr[i] = [a, b]
    
arr = sorted(arr, key=lambda x:x[1])
arr = np.array(arr)

ans = "Yes"
for i in range(len(arr)):
  if np.sum(arr[:i+1], axis=0)[0] > arr[i][1]:
    ans = "No"
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter

n = int(input())
m = []
for i in range(n):
    m.append([int(x) for x in input().split()])
m2 = sorted(m, key=itemgetter(1))
while len(m2) > 0:
    s = 0
    for x in m2:
        s += x[0]
    if s > m2[-1][1]:
        print("No")
        sys.exit(0)
    m2.pop()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  pos=bisect.bisect(B,b)
  A.insert(pos,a)
  #B.insert(pos,b)
  bisect.insort(B,b)

t = 0
for i in range(N):
  t += A[i]
  if t > B[i]:
    print("No")
    sys.exit()
    
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]

    is_possible = True
    for e in l:
        if sum([i[0] for i in l if i[1] <= e[1]]) > e[1]:
            is_possible = False
            break

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
a = [0]*N
b = [0]*N
for i in range(N):
    a[i], b[i] = [int(x) for x in input().split()]


p = list(itertools.permutations(zip(a, b)))

is_ok = False
for i in range(len(p)):
    w = 0
    for j in range(N):
        if w + p[i][j][0] <= p[i][j][1]:
            w += p[i][j][0]
            if j == N-1:
                is_ok = True
        else:
            break


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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    A = [0 for x in range(N)]
    B = [0 for x  in  range(N)]
    for i in range(N):
        l = list(map(int,input().split(" ")))
        A[i] = l
    sortedA=sorted(A, key= lambda x: x[1])
    ans='No'
    for i,x in enumerate(sortedA):
        s=0
        for ind in range(i+1):
            s+=sortedA[ind][0]
        if  s>x[1]:
            return 'No'
    return 'Yes'
    
if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools 
N = int(input())
X = [list(map(int, input().split())) for n in range(N)]
X = list(itertools.permutations(X, len(X)))
isOK = False
for x in X:
    cnt = 0
    check = []
    for n in x:
        cnt += n[0]
        #print('x:{}, cnt:{}, limit:{}'.format(x,cnt,n[1]))
        if cnt > n[1]:
            check.append(0)
        else:
            check.append(1)
    if sum(check) == len(x):
        isOK = True
        break
if isOK:
    print('Yes')
else:
    print('No')

Submission status: Time Limit Exceeded

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

x=np.array(x)
y=np.array(y)
z=np.vstack((x,y))
zz=np.argsort(z[1,:])[::-1]
z=z[:,zz]


left=z[1,0]
flag='Yes'
for i in range(N):
  
  if min(left,z[1,i])<sum(z[0,i:]):
    flag='No'

    break
  else:
    left=z[1,i]-z[0,i]
print(flag)

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    limits = set([e[1] for e in l])

    is_possible = True
    for e in l:
        if sum([i[0] for i in l if i[1] <= e[1]]) > e[1]:
            is_possible = False
            break

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def mysort(lol) :
    l = len(lol)
    if l == 1 :
        return lol
    else :
        return merge(mysort(lol[:l//2]), mysort(lol[l//2:]))

def merge(lol1, lol2) :
    ans = []
    l1, l2 = lol1, lol2
    while l1 != [] and l2 != [] :
        if l1[0][1] > l2[0][1] :
            ans.append(l2.pop(0))
        else :
            ans.append(l1.pop(0))
    else :
        if l1 != [] :
            ans += l1
        else :
            ans += l2
    return ans

ablist = [list(map(int, input().split())) for _ in range(n)]
ablist = mysort(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 sys
import bisect

N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int, input().split())
  pos=bisect.bisect(B,b)
  A.insert(pos,a)
  B.insert(pos,b)

t = 0
for i in range(N):
  t += A[i]
  if t > B[i]:
    print("No")
    sys.exit()
    
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
tasks = []

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


def modify_order(l, i):
    for j in range(len(l) - 1, i, -1):
        if l[j-1][1] > l[j][1]:
            l[j-1], l[j] = l[j], l[j-1]

def sort(l):
    for i in range(0, len(l) - 1):
        modify_order(l, i)        
        
sort(tasks)

time = 0

for i in range(N):
    time += tasks[i][0]
    if time > tasks[i][1]:
        print("No")
        sys.exit()
        
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import bisect

n = int(input())

a, b = map(int, input().split())
task_lis = [[b, a]]
sum_a = 0
ch_over = 1


for i in range(n-1):
    a, b = map(int, input().split())
    if a > b:
        ch_over = 0
        break
    else:
        pass
    ok2 = bisect.insort_right(task_lis,[b, a])


for i in range(n):
    if ch_over == 0:
        break
    else:
        pass
    sum_a += task_lis[i][1]
    if task_lis[i][0] < sum_a:
        ch_over = 0
        break

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

Submission status: Time Limit Exceeded

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

#下限
all_time = 0
f = n

while(True):
    #上限
    up = min(b)
#    print("up:"+str(up))
#    print(b)
    for i in range(n):
#        print(i)
        if b[i] == up:
            all_time += a[i]
            del b[i]
            del a[i]
#            print(b)
            f -= 1
        if i >= f-1:
            break
            # if i != n-1:
            #     i -= 1
    
    if all_time > up:
        print("No")
#        print(all_time)
        break

#    print("length:"+str(len(b)))
    if len(b) == 0:
        print("Yes")
        break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [list(input().split( )) for i in range(N)]
#print(s[1][0])
t = sorted(s, key=lambda x:int(x[1]))
#print(t)
count = 0
for i in range(len(t)):
  sum_i = sum([int(t[j][0]) for j in range(0, i+1)])
  if int(t[i][1]) < sum_i :
    count += 1
if count != 0:
  print("No")
else:
  print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    l = [list(map(int, input().split())) for i in range(n)]
    limits = set([ e[1] for e in l])

    is_possible = True
    for e in limits:
        if sum([i[0] for i in l if i[1] <= e]) > e:
            is_possible = False
            break

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

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

    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())
A=[]
B=[]
str='Yes'
total=0
time=0
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)

time=min(B)
for j in range(N):
    if time<=min(B):
        time = min(B)
    K=B.index(min(B))
    B[K]=1000000000000
    total +=A[K]
    if total>time:
        str='No'
print(str)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
for i in range(n):
    if b[i][0]<sum(c[:i+1]):
        ans="No"
        break
print(ans)

Submission status: Time Limit Exceeded

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

#下限
all_time = 0
f = n

while(True):
    #上限
    up = min(b)
#    print("up:"+str(up))
    s_time = 0
#    print(b)
    for i in range(n):
#        print(i)
        if b[i] == up:
            s_time += a[i]
            del b[i]
            del a[i]
#            print(b)
            f -= 1
        if i >= f-1:
            break
            # if i != n-1:
            #     i -= 1
    
    all_time += s_time
    if all_time > up:
        print("No")
#        print(all_time)
        break

#    print("length:"+str(len(b)))
    if len(b) == 0:
        print("Yes")
        break

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=[]
x=[]
D = [[0 for i in range(2)] for j in range(N)]#N×"2"の行列Dを作る
for i in range(0,N):
    x=input().split(" ")
    for j in range(0,2):#i行目の成分を入力
        D[i][j]=int(x[j])

D.sort(key=lambda p:p[1])#2列目の成分でソート

x=0
for i in range(0,N):
    x=x+D[i][0]#経過時間
    y=D[i][1]#締め切り時刻
    if x>y:
        n=1
        break
    else:
        z=0
        for j in range(0,N):
            z=z+D[j][0]
            if z<=D[N-1][1]:
                n=0
if n==1:
    print('No')
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):
    if max(b) < sum(a):
        print("No")
        break
    a.pop(b.index(max(b)))
    b.pop(b.index(max(b)))
else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
import fractions
import numpy as np

N = int(input())

AB = np.zeros([N,2])

for i in range(N):
    AB[i,:] = list(map(int, input().split()))
    if AB[i,0] > AB[i,1]:
        print('No')
        sys.exit()

# 締切の近い順に並び替え
AB = AB[np.argsort(AB[:,1])]

time = 0

for i in range(N):
    time += AB[i,0]
    if time > AB[i,1]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a[i][1],a[i][0]=map(int,input().split())
b=sorted(a)
c=[b[i][1] for i in range(n)]
ans="Yes"
for i in range(n):
    if b[i][0]<sum(c[:i+1]):
        ans="No"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import bisect

N=int(input())
A=[]
B=[]
sumA=0
for i in range(N):
  a,b=map(int, input().split())
  pos=bisect.bisect(B,b)
  A.insert(pos,a)
  B.insert(pos,b)
  sumA+=a

if sumA > B[-1]:
  print("No")
  sys.exit()

t = sumA
for i in range(N-2,-1,-1):
  t -= A[i+1]
  if t > B[i]:
    print("No")
    sys.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
    A.append(a)
    B.append(b)
def merge_sort(arr,b):
    if len(arr) <= 1:
        return (arr,b)

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]
    leftt =b[:mid]
    rightt = b[mid:]

    # 再帰的に分割を行う
    left,leftt = merge_sort(left,leftt)
    right,rightt = merge_sort(right,rightt)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right,leftt,rightt)


def merge(left, right,leftt,rightt):
    merged = []
    mergedd = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            mergedd.append(leftt[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            mergedd.append(rightt[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
        mergedd.extend(leftt[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
        mergedd.extend(rightt[r_i:])
    return (merged,mergedd)
B,A = merge_sort(B,A)
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:
n = int(input())
a_lst = []
b_lst = []
sum_lst = []

for i in range(0, n):
    a, b = [int(elem) for elem in input().split()]
    a_lst.append(a)
    b_lst.append(b)

tmp = zip(b_lst, a_lst)
tmp = sorted(tmp)
b_lst, a_lst = zip(*tmp)   

for i in range(0, len(a_lst)):
    sum_lst.append(sum(a_lst[:i+1]))

flag = 0
for a, b in zip(sum_lst, b_lst):
    if a > b:
        flag = 1

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

flag = True
now_time = 0
while tasks != []:
  a,b = tasks.pop(0)
  if now_time + a > b:
    flag = False
    break
  else:
    now_time = now_time + a
if flag:
  print("Yes")
else:
  print("No")

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

    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:
import bisect

n = int(input())


a, b = map(int, input().split())
task_lis = [[b, a]]

k = 1

for i in range(n-1):
    a, b = map(int, input().split())
    ok2 = bisect.insort_right(task_lis,[b, a])

sum_a = 0

ch_over = 1
for i in range(n):
    sum_a += task_lis[i][1]
    if task_lis[i][0] < sum_a:
        ch_over = 0
        break

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

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
    else:
      count += 1
      ans = "Yes"
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def dec(X, d):
    X[1] -= d
    return X


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

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

while task:
    if task[0][1] - task[0][0] < 0:
        print("No")
        exit()
    task = list(map(lambda x: dec(x, task[0][0]), task[1:]))

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
list = []
for i in range(n):
  a,b = map(int, input().split())
  if a > b:
    print('No')
    sys.exit()
  list += [(b,a)]
  
list.sort()
for i,ele in enumerate(list):
  if sum([a[1] for a in list[:i+1]]) > list[i][0]:
    print('No')
    sys.exit()
print('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(100):

    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())
A=[]
B=[]
for i in range(N):
  a,b = input().split()
  A.append(int(a))
  B.append(int(b))
for j in range(N-1):
  for i in range(N-1):
    if B[i] > B[i + 1]:
      B[i], B[i + 1] = B[i + 1], B[i]
      A[i], A[i + 1] = A[i + 1], A[i]
count = 0
sum = 0
for i in range(N):
  sum = sum + A[i]
  if sum > B[i]:
    count = 1
    break
if count == 0:
  print("Yes")
else:
  print("No")

Submission status: Time Limit Exceeded

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

time=min(B)
for j in range(N):
    if time<=min(B):
        time = min(B)
    K=B.index(min(B))
    B.pop(K)
    total +=A[K]
    if total>time:
        str='No'
print(str)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[3]:


import numpy as np


# In[25]:


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


# In[26]:


data = np.array(data)


# In[27]:


sorted_data = data[np.argsort(data[:, 1])]


# In[28]:


flag = 0
for i in range(N):
    if sum(sorted_data[:i+1, 0]) > sorted_data[i, 1]:
        flag = 1
        break

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


# In[ ]:

Submission status: Time Limit Exceeded

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

down = 0
#下限
all_time = 0
stack = 0

while(True):
    up = 100000000
    #上限
    for i in range(n):
        if b[i] < up and b[i]>down:
            up = b[i]

#    print("up:"+str(up))
    s_time = 0
    for i in range(n):
        if b[i] == up:
            s_time += a[i]
            stack += 1
    
    all_time += s_time
    if all_time > up:
        print("No")
#        print(all_time)
        break

    if stack == n:
        print("Yes")
        break
    down = up