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: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
count =0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
    else:
        print("No")
        count = 1
if tt <= dat[N-1][1] and count == 0:
    print("Yes")

Submission status: Wrong Answer

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] = [b[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    sums+=c[i][1]
    print(sums)
    if c[i][0] < sums:
        correct=0
        break
        
if correct:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
    else:
        print("No")
if tt <= dat[N-1][1]:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
W=[]
for i in range(N):
    a,b=map(int,input().split())
    W.append([b-a,a,b])
W.sort()
ans=0
for i in range(N):
    ans+=W[i][1]
    if ans > W[i][2]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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] = [b[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    sums+=c[i][1]

    if c[i][0] >sums:
        correct=0
        break
        
if correct:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for i in range(N):
    b, a = map(int, input().split())
    if a in dic.keys():
        dic[a] += b
    else:
        dic[a] = b
for key, value in dic.items():
    if key < value:
        print(key, value)
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
while (gap>0):
    for i in range(gap,n):
        key=b[i]
        l=a[i]
        if(key<b[i-gap]):
            j=i
            while True:
                b[j]=b[j-gap]
                a[j]=a[j-gap]
                j-=gap
                if(j<gap or key>=b[j-gap]):
                    break
            b[j]=key
            a[j]=l
        gap=int((gap-1)/3)
for i in range(n):
    e+=a[i]
    if(e>b[i]):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
 
#print(dat,tt)
if tt <= dat[N-1][1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
def shellsort(b):
    while (gap>0):
        for i in range(gap,n):
            key=b[i]
            l=a[i]
            if(key<b[i-gap]):
                j=i
                while True:
                    b[j]=b[j-gap]
                    a[j]=a[j-gap]
                    j-=gap
                    if(j<gap or key>=b[j-gap]):
                        break
                b[j]=key
                a[j]=l
            gap=int((gap-1)/3)
for i in range(n):
    e+=a[i]
    if(e>b[i]):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import collections

N = input().strip()
N = int(N)
dic = collections.defaultdict(lambda: 0)

for i in range(N):
    x,y = input().strip().split(" ")
    x = int(x)
    y = int(y)

    dic[y] += x

prev_time = 0
result = "Yes"

for k,v in dic.items():
    if v+prev_time > k:
        result = "No"
        break
    prev_time += v

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
 
#print(dat)
if ass == N:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
AList = []
BList = []
for i in range(N):
    A, B = map(int, sys.stdin.readline().split())
    AList.append(A)
    BList.append(B)
sAList = sorted(AList, key=lambda k:BList, reverse=True)
sBList = sorted(BList)

temp = 0
isNG = False
for i in range(N):
    temp += AList[i]
    if temp > BList[i]:
        isNG = True
        break
print(["Yes","No"][isNG])

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
AList = []
BList = []
for i in range(N):
    A, B = map(int, sys.stdin.readline().split())
    AList.append(A)
    BList.append(B)
sAList = sorted(AList, key=lambda k:BList, reverse=True)
sBList = sorted(BList)

temp = 0
isNG = False
for i in range(N):
    temp += AList[i]
    if temp > BList[i]:
        isNG = True
        break
print(["Yes","NO"][isNG])

Submission status: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
 
#print(dat)
if tt <= dat[N-1][1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

time=0
for i in range(N):
    time+=ls[i][0]
    print(time,i)
    if time > ls[i][1]:
        print("No")
        break
    if i == N-1:
        print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
 
dat = []
 
for i in range(N):
    a,b = map(int,input().split())
    dat.append((a,b))
dat.sort(key = lambda x:x[1])
 
tt = 0
ass = 0
for i in range(N):
    if tt <= dat[i][1]:
        ass += 1
        tt = tt + dat[i][0]
 
#print(ass)
if tt <= dat[N-1][0]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)], key = lambda x:x[1])


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: Wrong Answer

Solution code:
from operator import itemgetter
import sys
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
 
#print(listA)
 
listB = sorted(listA)
#print(listB)
listC = sorted(listB, key=itemgetter(1))
#print(listC)
flag = 0
time = 0
 
for i in range(N-1):
	time += listC[i][0]
	#print(time)
	if time > listC[i][1]:
		print('No')
		sys.exit()
 
print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
task_lis = sorted([[int(i) for i in input().split()] for _ in range(n)])


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: Wrong Answer

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

cost = ab[0][0]
limit = ab[0][1]

for i in range(1, n):
    cost += ab[i][0]
    limit = ab[i][1]
    if limit < cost:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
 
#print(listA)
 
listB = listA
#print(listB)
listC = sorted(listB, key=itemgetter(1))
#print(listC)
flag = 0
time = 0
 
for i in range(N-1):
	time += listC[0][0]
	#print(time)
	listC.pop(0)
	if time > listC[0][1]:
		flag = 1
		break
 
if flag==0:
	print('Yes')
elif flag==1:
	print('No')

Submission status: Wrong Answer

Solution code:
N  = int(input())

AB = []
time = 0

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

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

for i in range(N):

    time += NewAB[i][0]

    if time > NewAB[i][1]:
        print(time)
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
for i in range(n):
    a,b = list(map(int,input().split()))
    lis.append([a,b])
lis.sort(key=lambda x:x[1])
print(lis)
ans = 0
time = 0
for item in lis:
    time += item[0]
    if time > item[1]:
        ans += 1

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

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
task = {}
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
for b in sorted(task.keys()):    
    s += task[b]
    if b<s:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

s_w_l = list(map(lambda x: x[1], s_w))
s_w_c = list(map(lambda x: x[0], s_w))

import numpy as np
if all(np.cumsum(np.array(s_w_c)) <= np.cumsum(np.array(s_w_l))):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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


def yes_or_no():
    sorted_index = np.argsort(B)
    sum_A = [A[sorted_index[0]]]
    for i in range(1, N):
        next_num = sum_A[i-1] + A[sorted_index[i]]
        sum_A.append(next_num)
        if next_num > B[sorted_index[i]]:
            return 0
        
    return 1

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

if __name__ == '__main__':
    n = int(input())
    works = np.array([[int(i) for i in input().split()] for i in range(n)])
    col_num = 1
    sorted_works = works[np.argsort(works[:, col_num])]
    print(sorted_works)
    time = 0
    for i in range(n):
        time += sorted_works[i][0]
        if time > sorted_works[i][1]:
            print("No")
            sys.exit()

        else:
            None

    print("Yes")

Submission status: Wrong Answer

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

L.sort()
R=0
An='Yes'
for j in range(N):
  if L[j][0]<R:
    An='No'
    break
  R+=L[j][1]
print(An)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())  

A = np.zeros(N) 
B = np.zeros(N) 

for i in range(N):
    A[i], B[i] = map(int, input().split())
    
B1 = B[np.argsort(B)]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
def shellsort(b):
    while (gap>0):
        for i in range(gap,n):
            key=b[i]
            l=a[i]
            if(key<b[i-gap]):
                j=i
                while True:
                    b[j]=b[j-gap]
                    a[j]=a[j-gap]
                    j-=gap
                    if(j<gap or key>=b[j-gap]):
                        break
                b[j]=key
                a[j]=l
            gap=int(gap/3)
for i in range(n):
    e+=a[i]
    if(e>b[i]):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
task = {}
for i in range(N):
    tmp = input().split()
    A = int(tmp[0])
    B = int(tmp[1])
    task[B] = A
    # if B in task:
    #     task[B].append(A)
    # else:
    #     task[B] = [A]

s = 0
for b in sorted(task.keys()):    
    s = task[b]
    if b<s:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:

from operator import itemgetter

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] = [b[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    if sums > c[i][0]:
        correct=0
        break
    else:
        sums += c[i][1]


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

Submission status: Wrong Answer

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]), reverse = True)
#print(t)
count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  print(sum1)
  print(int(t[i][1]))
  if int(t[i][1]) > sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
if count == 0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

for i in list(set(B)):
    tmp = 0
    for j in range(N):
        if i == B[j]:
            tmp += A[j]
    if tmp > i:
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
print(li)
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
def shellsort(b):
    while (gap>0):
        for i in range(gap,n):
            key=b[i]
            l=a[i]
            if(key<b[i-gap]):
                j=i
                while True:
                    b[j]=b[j-gap]
                    a[j]=a[j-gap]
                    j-=gap
                    if(j<gap or key>=b[j-gap]):
                        break
                b[j]=key
                a[j]=l
            gap=int(gap/3)
for i in range(n):
    e+=a[i]
    f+=b[i]
    if(e>f):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

for i in range(N):
    A,B=map(int,input().split())
    lst.append([A,B])
lst.sort(key=lambda x: x[1])

def judge(N):
    worktime=0
    for i in range(N):
        if worktime > lst[i][1]:
            return('No')
        worktime += lst[i][0]
        if (i+1)==N:
            return('Yes')        
print(judge(N))

Submission status: Wrong Answer

Solution code:
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().rstrip())
    
    AB = []
    for i in range(N):
        AB.append([int(x) for x in stdin.readline().rstrip().split()])
    AB.sort(key=lambda x:x[1])
    
    ans = "Yes"
    # print(AB)
    for i in range(N):
        ab = AB[0]
        AB = AB[1:]
        AB = [[x,y-ab[0]] if x <= y-ab[0] else [0,0] for x, y in AB ]
        if len(AB) != 0 and AB[0] == [0,0]:
            ans = "No"
        # print("=======")
        # print(AB)
    print(ans)

Submission status: Wrong Answer

Solution code:
import scipy as sp
N = int(input())
l = []
for i in range(N):
    l.append(list(map(int, input().split())))

l = sp.array(sorted(l, key=lambda x: x[1]))

a = sp.cumsum(l[:,0])
b = l[:,1]

c = b-a
t = True
for i in c:
    if i < 0:
        t = False
        print("No")

if t:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
def shellsort(b):
    while (gap>0):
        for i in range(gap,n):
            key=b[i]
            l=a[i]
            if(key<b[i-gap]):
                j=i
                while True:
                    b[j]=b[j-gap]
                    a[j]=a[j-gap]
                    j-=gap
                    if(j<gap or key>=b[j-gap]):
                        break
                b[j]=key
                a[j]=l
for i in range(n):
    e+=a[i]
    f+=b[i]
    if(e>f):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

N = int(input())
A = [0]*N
B = [0]*N

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

B_desc = sorted(B, reverse=True)
limit = B_desc[0]

for i in B_desc:
    idxs = [i for i, x in enumerate(B_desc) if x == i]
    for j in idxs:
        limit - A[j]

if limit > 0:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
number = []
for i in range(N):
    S, P = input().split(" ")
    number.append([S,P])


number.sort(key=lambda x: x[1], reverse=True)
number.sort(key=lambda x: x[0])

sum=0
for i in range(N):
    #print(number[i][0])
    sum+=int(number[i][0])
    if(sum<int(number[i][1])):
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
len=len(B)
str='Yes'
total=0
time=0
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
B.sort()
AB=B+A
time=min(B)
for j in range(N):
    time += AB[j]
    total +=AB[j+len+1]
    if total>time:
        str='No'
print(str)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys

input = sys.stdin.readline

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

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

done = 10**9
pstart = 10**9
time = 0
for a, b in reversed(AB):
    done = min(pstart,b)
    pstart = done-a
    time += a
if AB[N-1][1]>=time:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
cost = []
lim = []
a = 0
b = 0
for i in range(n):
  a,b = map(int,input().split())
  cost.append(a)
  lim.append(b)
cost = np.array(cost)
lim = np.array(lim)
cost = cost[np.argsort(lim)[::-1]]
lim = lim[np.argsort(lim)[::-1]]
if sum(cost) > lim[0]:
  print("No")
else:
  temp = 0
  for i in range(len(lim)-1):
    temp = lim[i] - cost[i]
    if temp <= 0:
      print("No")
      break
    elif temp < lim[i+1]:
      lim[i+1] = temp
    else:
      continue
  if lim[-1] >= cost[-1]:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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,0]) > a[i,1]:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019 6/22
# ABC 131 D MEgalomania

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

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

work.sort()

time = 0

is_ok = True

for i in range(N):
    time += work[i][2]
    if time > work[i][1]:
        is_ok = False
        break

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

Submission status: Wrong Answer

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

cost = ab[0][0]
limit = ab[0][1]

for i in range(1, n):
    cost += ab[i][0]
    limit = ab[i][1]
    if limit < cost:
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A =[]
B = []
C = []
for i in range(N):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
for i in range(N):
    C.append([A[i],B[i]])
A.sort()
B.sort()
#print(A,B)
ass = 0
tt = 0
for i in range(N):
    if tt <= B[i]:
        ass += 1
        tt = tt + A[i]

#print(ass)
if tt <= B[N-1]:
    print("Yes")
elif tt > B[N-1]:
    print("No")

Submission status: Wrong Answer

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

a = [ab[i][0] for i in range(n)]
b = [ab[i][1] for i in range(n)]

now = 0;
flag = 1;
for i in range(n):
    current = b.index(max(b))
    if i==0:
        now = b.pop(current)-a.pop(current)
    else:
        if b[current] < now:
            flag = 0
            break
        else:
            now = min(now,b.pop(current))-a.pop(current)
    if (current < 0):
        flag = 0
print("Yes" if flag else "No")

Submission status: Wrong Answer

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]), reverse = True)
#print(t)
count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  if int(t[i][1]) > sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
if count != 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
number = []
for i in range(N):
    S, P = input().split(" ")
    number.append([S,P])


number.sort(key=lambda x: x[1], reverse=True)
number.sort(key=lambda x: x[0])

sum=0
for i in range(N):
    #print(number[i][0])
    sum+=int(number[i][0])
    if(sum>int(number[i][1])):
        print("No")
        sys.exit()
print("Yes")

Submission status: Wrong Answer

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

L.sort()
R=0
An='Yes'
for j in range(N):
  if L[j][0]<R:
    An='No'
    break
  R+=L[j][1]
print(An)

Submission status: Wrong Answer

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

cost = ab[0][0]
limit = ab[0][1]

for i in range(1, n):
    cost += ab[i][0]
    limit = ab[i][1]
    if limit < cost:
        print('No')
        exit()
else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
len=len(B)
str='Yes'
total=0
time=0
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
B.sort()
AB=B+A
time=min(B)
for j in range(N):
    time += AB[j]
    total +=AB[j+len]
    if total>time:
        str='No'
print(str)

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[]
listb=[]
listc=[]
for i in range(n):
  a,b=map(int,input().split())
  lista.append(a)
  listb.append(b)
  listc.append([b-a,i])
listc.sort()
flag=1
x=0
t=0
for j in range(n):
  if(x+lista[listc[j][1]]>listb[listc[j][1]]):
    flag=0
    break
  x=x+lista[listc[j][1]]
if(flag==1):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

for i in range(N):
    A,B=map(int,input().split())
#    if A>B:
#        print('No')   
    lst.append([A,B,B-A])
lst.sort(key=lambda x: x[2])

def judge(N):
    worktime=0
    for i in range(N):
        if worktime > lst[i][1]:
            return('No')
        worktime += lst[i][0]
        if (i+1)==N:
            return('Yes')
        
print(judge(N))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(4100000)

n = int(input())

la = []
for i in range(n):
	a = [int(i) for i in input().split()] 
	if a[0] > a[1]:
		print("No")
		sys.exit()
	la.append(a)

s = la[0][1]
t = la[0][0]

for i in range(1, n):
	s = max(s, la[i][1])
	t += la[i][0]
	if t > s:
		print("No")
		sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

a_b_lis = [0] * N

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

count = 0
#print(a_b_lis)
a_b_lis = sorted(a_b_lis, key=lambda x: (x[1], -x[0]))

on_time = True
for item in a_b_lis:
    if item[0] + count <= item[1]:
        count += item[0]
        on_time = True
    else:
        on_time = False

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]
gap=0
e=0
f=0
m=0
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
while (gap<=n/9):
    gap=gap*3+1
def shellsort(b):
    while (gap>0):
        for i in range(gap,n):
            key=b[i]
            if(key<b[i-gap]):
                j=i
                while True:
                    b[j]=b[j-gap]
                    a[j]=a[j-gap]
                    j-=gap
                    if(j<gap or key>=b[j-gap]):
                        break
                b[j]=key
for i in range(n):
    e+=a[i]
    f+=b[i]
    if(e>f):
        m=1
if(m==1):
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB = sorted(AB, key=lambda ab: (-ab[1], -ab[0]))
    t = AB[0][1]
    for ab in AB:
        if t < 0:
            break
        if ab[1] < t:
            t = ab[1]
        else:
            t -= ab[0]
    if t < 0:
        print('No')
    else:
        print('Yes')
main()

Submission status: Wrong Answer

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

cost = ab[0][0]
limit = ab[0][1]

for i in range(1, n):
    cost += ab[i][0]
    limit = ab[i][1]
    if limit > cost:
        print('Yes')
    else:
        print('No')
        exit()

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB,key = lambda x:x[1])
S=0
flag=0
for i in range(N):
    S+=AB[i][0]
    if S>= AB[i][1]:
        print("No")
        flag=1
        break
if flag == 0:
    print("Yes")

Submission status: Wrong Answer

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]), reverse = True)
#print(t)
count = 0
sum1 = sum([int(t[j][0]) for j in range(len(t))])
for i in range(len(t)):
  if int(t[i][1]) < sum1 :
    sum1 = sum1 - int(t[i][0])
  else:
    count += 1
if count != 0:
  print("No")
else:
  print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
lis = []
a = 0
b = 0
for i in range(n):
    a,b = map(int,input().split())
    lis.append(b)
    dic.setdefault(b,a)

lis = sorted(lis)
c=0
d=0
ans = "Yes"
for i in lis:
    c += dic[i]
    if b < c:
        ans = "No"
        break;

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
def maxin(a):
    maxIndex = [i for i, x in enumerate(a) if x == max(a)]
    return(maxIndex)
N=int(input())
A=[]
B=[]
for n in range(N):
    a,b=(int(x) for x in input().split())
    A.append(a)
    B.append(b)
c=0
T=max(B)
for n in range(N):
    yari=maxin(B)
    dai=max(B)
    if dai>T:
        c=1
        break
    for l in yari:
        T=T-A[l]
    for l in yari:
        B[l]=0
        A[l]=0
    if sum(A)==0:
        break
if c==1:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
A =[]
B = []
C = []
for i in range(N):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
for i in range(N):
    C.append([A[i],B[i]])
A.sort()
B.sort()
#print(A,B)
ass = 0
tt = 0
for i in range(N):
    if tt <= B[i]:
        ass += 1
        tt = tt + A[i]

#print(ass)
if tt <= B[N-1]:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

a_b_lis = [0] * N

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

count = 0
#print(a_b_lis)
a_b_lis = sorted(a_b_lis, key=lambda x: (x[1], x[0]))

on_time = True
for item in a_b_lis:
    if item[0] + count <= item[1]:
        count += item[0]
        on_time = True
    else:
        on_time = False

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

Submission status: Wrong Answer

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

A.sort()
B.sort()

C = A.copy()
for i in range(len(C)-1):
    C[i+1] = C[i] + A[i+1]

D = [x - y for (x, y) in zip(B, C)]

if min(D) >= 0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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] = [b[i]-a[i],a[i]]
   
c.sort()
sums = 0
correct = 1
for i in range(N):
    if sums > c[i][0]:
        correct=0
        break
    else:
        sums += c[i][1]


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

Submission status: Wrong Answer

Solution code:
n = int(input())
# A = []
# B = []
AB = []

for i in range(n):
    ab = list(map(int, input().split()))
    AB.append(ab)

#print(AB)
#print(sorted(AB, key=lambda x: x[1]))

current = 0
ans = True
for i in range(n):
    time = AB[i][0]
    now = current + time

    if now <= AB[i][1]:
        current += time
        continue
    else:
        ans = False
        break

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB = sorted(AB, key=lambda ab: (-ab[1], ab[0]))
    t = AB[0][1]
    for ab in AB:
        if ab[1] < t:
            t = ab[1]
        else:
            t -= ab[0]
    if t < 0:
        print('No')
    else:
        print('Yes')
main()