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())
task = []
task_sum = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    task.append([a, b, b-a])
task.sort(key=lambda x: (x[2], x[0]))
sum = 0
flag = True
for i in range(n):
    if sum + task[i][0] > task[i][1]:
        flag = False
        break
    sum += task[i][0]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche ={}
for work in works:
    if work[1] not in sche:
        sche[work[1]] = work[0]
    else:
        sche[work[1]] += work[0]
acc = 0
for k,v in sche.items():
    acc += v
    if acc > k:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
G = [list(map(int,input().split())) for k in range(N)]
G = sorted(G,key = lambda x: x[1])
now = 0

for k in range(N):
    if now > G[k][1]:
        print("No")
        exit(0)
    else:
        now += G[k][0]

if now > G[N-1][1]:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

max_B = 0
total_A = 0
for i in range(N):
    A, B = map(int, input().split())
    total_A += A
    max_B = max(B, max_B)

if total_A <= max_B:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import re


def inputs(): return [int(s) for s in input().split()]


def main():
    N = input()
    AB = [inputs() for _ in range(int(N))]
    AB.sort(key=lambda x: x[1])
    print(AB)
    time = 0
    for a, b in AB:
        time += a
        print(time, b)
        if time > b:
            return 'No'
    return 'Yes'


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

Submission status: Wrong Answer

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

hoge.sort()
  
for i in range(n):
  #print(hoge[i][0],hoge[i][1])
  time=time+hoge[i][1]
  if(time>=hoge[i][0]):
    ans+=1
    
if(ans==0):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

m = 0
for i in range(N):
    a,b = map(int,input().split())
    dic[b] += a
    if m < b: m = b

for k,v in dic.items():
    m -= v
    
if m < 0:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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

lst.sort()
lst = lst + [[0, 0]]

time = lst[0][1]
i = 0
while i < N and time <= lst[i][0]:
    time += lst[i+1][1]
    i += 1

if i == N:
    print('yes')
else:
    print('no')

Submission status: Wrong Answer

Solution code:
N = int(input())
time = []
limit = []
is_able = True
for i in range(N):
    a, b = (int(x) for x in input().split())
    time.append(a)
    limit.append(b)

for j in range(N):
    limax = 0
    loca = 0
    for k in range(N-j):
        if limit[k] >= limax:
            limax = limit[k]
            loca = k
        if sum(time) > limax:
            is_able = False
    time.remove(time[loca])
    limit.remove(limit[loca])

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

Submission status: Wrong Answer

Solution code:
N = int(input())
table = []
for _ in range(N):
    a,b = map(int, input().split())
    if a > b:
        print('No')
        exit()
    table.append((a,b-a))

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

time = 0
for i in range(N):
    if time < table[i][1]:
        print('No')
        exit()
    time += table[i][0]
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
job_dict = {}
for i in range(N):
    A,B = map(int,input().split())
    job_dict[B] = A
job_dict = sorted(job_dict.items())
time = 0
flag = 0
for i in job_dict:
    time += i[1]
    if i[0] < time:
        print('No')
        flag = 1
        break
if flag == 0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = 0
b = 0
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
if sum(A) > max(B):
  print("No")
else:
  print("Yes")
#print(sum(A))
#print(max(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
p = []
t = 0
for _ in range(n):
    a,b = map(int,input().split())
    t += a
    p.append([a,b])
#print(p)
p = sorted(p, key=lambda x:x[1])
et = p[-1][1]
if t <= et:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int (input())
time = []
limit = []
work_time = 0
flag = 0

for i in range(N):
    A , B = map(int , input().split())
    time.append(A)
    limit.append(B)
#print(limit.index(min(limit)))
for i in range(N):
    work_time += time[limit.index(min(limit))]
    if work_time > max(limit):
        flag = 1
        break
    del limit[limit.index(min(limit))]
if flag == 1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

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


def main():
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    mod_ab = sorted(ab, key=lambda x: (x[1], x[0]))
    time = 0
    b_max = mod_ab[-1][1]

    for ai, bi in mod_ab:
        time += ai

        if time > b_max:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

a.sort()
b.sort()

s = 0
ch = 0

for i in range(n):
    s += a[i]
    if s > b[i]:
        ch = 1
        break

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

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([y,y-x,x])
c = sorted(c)
s = -1
for i in range(len(c)):
    s+=c[i][2]
    if(s>c[i][0]):
        print('No')
        exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(input().split()))
    a[i][0]=int(a[i][0])
    a[i][1]=int(a[i][1])
    a[i][0],a[i][1]=a[i][1],a[i][0]
f=0
a.sort()
t=a[0][1]
for i in range(1,n):
    t+=a[i][1]
    if(t<=a[i][0]):
        continue
    else:
        f=1
if(f==1):
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

time = AB[0][1]
for i in range(1,N):
    if time-AB[i-1][0] < AB[i][1]:
        time = time-AB[i][0]
    else:
        time = AB[i][1]
time = time - AB[N-1][0]
if time < 0:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[list(map(int,input().split())) for i in range(N)]
T.sort(key=lambda x:x[1])
time=0
for i in range(N):
    time=time+T[i][0]
    if time>T[i][1]:
        print("No")
        break
if time<=T[N-1][1]:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
r=[]
for i in range(n):
    a,b=map(int,input().split())
    r.append(a)
    l.append(b)
m=max(l)
s=sum(r)
if s<=m and min(l)>=min(r):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche ={}
for work in works:
    if work[1] not in sche:
        sche[work[1]] = work[0]
    else:
        sche[work[1]] += work[0]
acc = 0
ans = "Yes"
for k,v in sche.items():
    acc += v
    if acc > k:
        ans = "No"
print(ans)

Submission status: Wrong Answer

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

import sys
from operator import itemgetter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
AB=[]
for i in range(N):
    a,b=MAP()
    AB.append((a, b))

AB.sort(key=itemgetter(1))
time=0
for i in range(N):
    a,b=AB[i]
    time+=a
    if b<time-1:
        No()
        exit()
Yes()

Submission status: Wrong Answer

Solution code:
def solve():
    n = int(input())
    task = [0]*n
    for i in range(n):
        a,b = map(int,input().split())
        task[i] = [a,b]
    
    task = sorted(task, key= lambda x : x[1])
    print(task)

    time = 0
    due = 0

    for i in range(n):
        time += task[i][0]
        due = max(due,task[i][1])
        if time > due:
            print('No')
            exit()
    
    print('Yes')
    return 0

solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    a.append(list(input().split()))
    a[i][0]=int(a[i][0])
    a[i][1]=int(a[i][1])
    a[i][0],a[i][1]=a[i][1],a[i][0]
f=0
a.sort()
t=a[0][1]
for i in range(1,n):
    t+=a[i][1]
    if(t>a[i][0]):
        f=1
if(f==1):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, fractions

readline = sys.stdin.readline

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

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

t = 0
for a, b in AB:
    t += a
    if t > b:
        print('NO')
        exit(0)

print('YES')

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
# 締切順にソート
AB = sorted(AB, key=lambda x: x[1])
now = 0
ans = 'Yes'

for i in range(N):
    now += AB[i][0]
    if now <= AB[i][1]:
        pass
    else:
        ans = 'No'

print(AB)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
works = []
for i in range(N):
    temp= list(map(int,input().split(" ")))
    works.append(temp)
works.sort(key=lambda x:x[1])
sche =defaultdict(lambda :0)
for work in works:
    sche[work[1]] += work[0]
acc = 0
ans = "Yes"
for k,v in sche.items():
    acc += v
    if acc > k:
        ans = "No"
print(ans)

Submission status: Wrong Answer

Solution code:
N = input()
N = int(N)
s = [[ int(i) for i in input().split()] for i in range(N)]
time = 0
hoge = "True"
s = sorted(s, key=lambda s:s[1])
for i in s:
    time += i[0]
    if time > i[1]:
        hoge = "No" 
        break

print(hoge)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}

for _ in range(N):
    A,B = map(int,input().split())
    if B in dic:
        dic[B] += A
    else:
        dic[B] = A

cum = 0    
flag = True

for bb in dic:
    aa = dic[bb]
    cum += aa
    if bb < aa:
        flag = False
        break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def f(AB):
    s = 0
    for a, b in sorted(AB, key=lambda x:x[1]):
        s += a

        if s > b:
            return 'No'

    return 'Yes'


def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for i in range(N)]
    print(f(AB))

Submission status: Wrong Answer

Solution code:
n = int(input())
task = []
task_sum = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    task.append([a, b, b-a])
task.sort(key=lambda x: x[2])
sum = 0
flag = True
for i in range(n):
    if sum + task[i][0] > task[i][1]:
        flag = False
        break
    sum += task[i][0]
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

                if k > B:
                    Limit[k] += A
                    if Limit[k] > k:
                        return 'No'
    return 'Yes'

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
c=sorted(ab, key=itemgetter(1), reverse=False)
f=True
t=0
for i in range(n):
    t = t + c[i][0]
    print(t)
    f=f and t<c[i][1]
if f:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input().strip())
a=[]
for i in range(N):
    array=list(map(int,input().strip().split()))
    a.append(array)
b=sorted(a, key=lambda x:x[1])
print(b)
n,t,f=0,0,0
while True:
    t+=b[n][0]
    if t>b[n][1]:
        f=1
        break
    n+=1
    if n==N:
        break
if f==1:
    print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list()
B = list()
sum_A = 0
max_B = 0
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

    sum_A += a
    max_B = b if max_B < b else max_B

if sum_A <= max_B:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1], reverse=True)
limit = ab[0][1] - ab[0][0]
for a, b in ab[1:]:
    limit = min(limit, b) - a
    if limit < 0:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <22/Jun/2019 05:59:03 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    arr = [0] * n
    ans = 'Yes'
    d = {}
    for i in range(n):
        arr[i] = get_array()
        if arr[i][0] > arr[i][1]:
            ans = 'No'
        if arr[i][1] not in d:
            d[arr[i][1]] = 0
        d[arr[i][1]] += arr[i][0]
    if ans == 'No':
        print(ans)
        return
    for i in d:
        if i < d[i]:
            ans = 'No'
            break
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
lis = []
for i in range(N):
    a,b = Is()
    lis.append([b,a])
lis = sorted(lis)
print(lis)
t = 0
for e in lis:
    t += e[1]
    if e[0] < t:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    data = sorted([(b, b-a, a) for a, b in zip(A, B)])
    curr = 0
    for i in range(N-1):
        b, c, a = data[i]
        curr += a
        if curr > b or curr > data[i+1][1]:
            no()
            return
    yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    Limit = dict()
    for i in range(N):
        A, B = map(int, input().split())
        Limit[B] = Limit.get(B,0) + A
        if Limit[B] > B:
            return 'No'
    return 'Yes'

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, A: "List[int]", B: "List[int]"):
    data = sorted([(b, b-a, a) for a, b in zip(A, B)])
    curr = 0
    for i in range(N-1):
        b, c, a = data[i]
        curr += a
        # print(c, a, b, "curr=", curr)
        if curr > data[i+1][1]:
            # print(curr, data[i+1])
            no()
            return
    yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import exit
INF = 10**21
N = int(input())
AB = [0 for i in range(N)]

for i in range(N):
    AB[i] = [int(n) for n in input().split()]
AB = sorted(AB, key=lambda x: x[0])
AB = sorted(AB, key=lambda x: -x[1])

now = AB[0][1]
for i in range(len(AB)):
    now -= AB[i][0]
if now < 0:
    print("No")
    exit()
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import fractions

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    n = int(input())
    task = [tuple(map(int, input().split())) for _ in range(n)]
    tmp = 0
    task.sort(key=lambda x:x[1])
    for a, b in task:
        tmp += a
        if tmp > b:
            print("NO")
            return
    print("YES")

main()

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
x=np.argsort(b)
g=0
f=0
for i in range(n):
    g+=a[x[i]]
    if b[x[i]]>g:
        f+=1
if f>0:
    print('No')
else:
    print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
time=0
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
c=sorted(set([a[i][1] for i in range(n)]))
for i in c:
    for x,y in a:
        if i==y:
            time+=x
            if time>y:
                print("No")
                exit()
print("Yes")

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
s = []
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  s.append([A,B])
m = sorted(list(set(x[1] for x in s)))
check = 0
for i in m:
  if sum([x[0] for x in s if x[1]<=i]) > i:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
s = []
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  s.append([A,B])
m = sorted(list(set(x[1] for x in s)))
used = 0
check = 0
for i in m:
  xs = [x for x in s if x[1]==i]
  used += sum([x[0] for x in xs]) 
  if used > i:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = {}
key = []
s = 0
for i in range(n):
    a, b = map(int, input().split())
    if b not in key:
        key.append(b)
        d.update({b:a})
    else:
        d[b] += a
    s += a
key.sort(reverse = True)
ans = True
for k in key:
    if k < s:
        ans = False
        break
    s -= d[k]
if ans:
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
s = []
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  s.append([A,B])
used = 0
now = 0
check = 0
for i in range(N):
  x = min([i[1] for i in s])
  y = min([i[0] for i in s if i[1]==x])
  used += y
  d = s.index([a for a in s if a==[y,x]][0])
  s.pop(d)
  if used > x:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

Submission status: Time Limit Exceeded

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

N=int(input().rstrip('\n'))
s = []
for _ in range(N):
  A,B = (int(x) for x in input().rstrip('\n').split())
  s.append([A,B])
used = 0
now = 0
check = 0
for i in range(N):
  x = min([i[1] for i in s])
  y = min([i[0] for i in s if i[1]==x])
  used += y
  d = s.index([a for a in s if a==[y,x]][0])
  s.pop(d)
  if used > x:
    check += 1
    print('No')
    break
if check == 0:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for i in range(n):
  a,b=ab.pop(0)
  if t+a <= b:
    t += a
  else:
    print('No')
    break
else:
  print('Yes')

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
a = 0
b = 0

for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
    a += li[0]
    b = max(b,li[1])
    l = sorted(l, key=lambda x: x[1])


if a > b:
    print('No')
    exit()

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

Sum = 0
for i in range(N):
    Sum = Sum + A[i]
    if Sum <= B[i]:
        continue
    else:
        print("No")
        quit()
print("Yes")

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

if all(sum(A[0:i+1]) <= B[i] for i in range(N)):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = [A[i] for i in np.argsort(B)]
B = np.sort(B)

if all(sum(A[0:i+1]) <= B[i] for i in range(N)):
    print("Yes")
else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
task = []
time = 0

for i in range(1,N+1) :
    A, B =input().split()
    task.append((int(A) ,int(B)))
    work = sorted(task, key = lambda x:(x[1]))
for i in range(N) :
    time += work[i][0]
    if time > work[i][1] :
        print("No")
        sys.exit()

print("Yes")

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from functools import lru_cache
import bisect
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    X = []
    for _ in range(N):
        a,b = map(int,input().split())
        bisect.insort(X,(b,a))

    x = 0
    X = deque(X)
    l = len(X)
    for _ in range(l):
        b,a = X.popleft()
        # print(b,a,x)
        if x + a > b:
            print("No")
            exit()

        x += a

    print("Yes")



if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
from collections import deque
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    X = []
    for _ in range(N):
        a,b = map(int,input().split())
        bisect.insort(X,(b,a))

    x = 0
    X = deque(X)
    while len(X) > 0:
        b,a = X.popleft()
        # print(b,a,x)
        if x + a > b:
            print("No")
            exit()

        x += a

    print("Yes")



if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    X = []
    for _ in range(N):
        a,b = map(int,input().split())
        bisect.insort(X,(b,a))

    x = 0
    while len(X) > 0:
        b,a = X.pop(0)
        # print(b,a,x)
        if x + a > b:
            print("No")
            exit()

        x += a

    print("Yes")



if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]
A = []
B = []
for i in range(n):
    a,b = map(int, stdin.readline().rstrip().split())
    A.append(a)
    B.append(b)

now = 0

for i in range(n):
    small = B.index(min(B))
    now += A[small]
    if now > min(B):
        print("No")
        exit()
    else:
        B[small] = INF

print("Yes")

Submission status: Time Limit Exceeded

Solution code:

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   A = []
   B = []
   for _ in range(N):
      a,b = map(int,input().split())
      A.append(a)
      B.append(b)
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N)]
time = 0
ab = sorted(ab, key=lambda x:x[1])
while ab:
  a, b = ab.pop(0)
  time += a
  if time <= b:
    pass
  else:
    print('No')
    exit()
print('Yes')