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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N =  I()
L = ILL(N)

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

dead = 0
now = 0
for a,b in L:
  now += a
  dead += b
  if now>dead:
    PE("NO")
P("YES")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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


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

weight = 0
for w, d in ab:
    print(weight, d)
    weight += w
    if weight > d:
        print("No")
        exit()
# print(weight, d)
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(input())

a = []
b = []

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a = np.array(a)
b = np.array(b)

diff = b - a

li = []
for x, y, z in zip(diff, a, b):
    li.append((x, y, z))

li.sort()
li = li[::-1]

stack = 0
for _, a, b in li:
    stack += a
    if stack > b:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(input())

a = []
b = []

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a = np.array(a)
b = np.array(b)

diff = b - a

li = []
for x, y, z in zip(diff, a, b):
    li.append((x, y, z))

li.sort()

stack = 0
for _, a, b in li:
    stack += a
    if stack > b:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

a = []
b = []

for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a.sort()
b.sort()

a = np.cumsum(a)

result = b - a

print("Yes" if result.min() >= 0 else "No")

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
b = []

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

works = []

for i in range(n):
    works.append((b[i], a[i]))

works.sort()

t = 0

for b, a in works:
    t += a
    if t > b:
        print('No')
        break

print("Yes")

Submission status: Wrong Answer

Solution code:
# ABC131 D Megalomania
import itertools

n = int(input())
ab_list = [[None] * 2 for i in range(n)]
for i in range(n):
    ab_list[i] = list(map(int, input().split()))

ab_list.sort(key=lambda x:(x[1]))
ab_list_T = [list(x) for x in zip(*ab_list)]

cum_iter = itertools.accumulate(ab_list_T[0])

flag = True
for _ in cum_iter:
    if _ > ab_list_T[1][i]:
        flag = False
    
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
print(AB)
AB.sort(key=lambda x: (x[1], -x[0]))
print(AB)
time = 0
for a, b in AB:
    time += a
    if time > b:
        print('No')
        break
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
n = int(input())

works = list()
for num in range(n):
    a = list(map(int, input().split()))
    works.append(a)

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

time = 0
limit = 0

for row in works:
    time += row[0]
    limit += row[1]
    if time >= limit:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

works = list()
for num in range(n):
    a = list(map(int, input().split()))
    works.append(a)

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

time = 0

counter = 0

for row in works:
    time += row[0]
    counter += 1
    if time >= row[1]:
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

works = list()
for num in range(n):
    a = list(map(int, input().split()))
    works.append(a)

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

time = 0

counter = 0

for row in works:
    time += row[0]
    counter += 1
    if time >= row[1]:
        print("No")
        break
if counter == len(works):
	print("Yes")

Submission status: Wrong Answer

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

m = sorted(l, key=lambda x: x[0])
work = 0
mx = 0
for i in range(N):
    mx = max(m[i][1], mx)

for i in range(N):
    work += m[i][0]
    if work > mx:
        print('No')
        exit()

print('Yes')

Submission status: Wrong Answer

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

m = sorted(l, key=lambda x: x[0])
work = 0
mx = -100
for i in range(N):
    work += m[i][0]
    mx = max(m[i][1], mx)

if mx > work:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

m = sorted(l, key=lambda x: x[0])
work = 0
mx = -100
for i in range(N):
    work += m[i][0]
    mx = max(m[i][1], mx)

if mx >= work:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
AB = []
for _ in range(N):
    A, B = map(int, input().split())
    AB.append([B-A, A, B])
AB.sort(key=itemgetter(0))
cnt = 0
for _, a, b in AB:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys

n = int(input())

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

ab = sorted(ab, key=lambda x:x[1], reverse=True)

d = []
d = deque(d)

while len(ab) > 0:
	d = deque([])
	d.append(ab.pop())
	while True:
		if len(ab) == 0:
			break
		if ab[-1][1] == d[0][1]:
			d.append(ab.pop())
		else:
			break
	num = 0
	for i in range(len(d)):
		a,b = d.pop()
		num += a
	if num > b:
		print('No')
		sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
A = deque()
for _ in range(N):
    a,b = list(map(int,input().split()))
    A.append([b,a])
A = list(A)
A.sort()
print(A)
time = 0
for i in A:
    time += i[1]
    if time > i[0]:
        print('No')
        exit()
print('Yes')

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

print("Yes" if max(b)>=sum(a) else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = ab2[0][0]

for i in range(n-1):
    if tmp <= ab2[i][1]:
        tmp += ab2[i+1][0]
    #print('tmp', tmp)
# print(ab2[n-1][1])
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = 0
tmp2 = 0
for i in range(n):
    if tmp <= ab2[i][1]:
        tmp += ab2[i][0]
    #print('tmp', tmp)
# print(ab2[n-1][1])
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = 0
for i in range(n):
    tmp += ab2[i][0]
    if tmp <= ab2[i][1]:
        continue
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = 0
for i in range(n):
    if tmp <= ab2[i][1]:
        tmp += ab2[i][0]
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
#print(ab2)
tmp = 0
for i in range(n):
    if tmp <= ab2[i][1]:
        tmp += ab2[i][0]
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
ab = [readints() for _ in range(n)]
# print(ab)
ab2 = sorted(ab, key=lambda x: x[1])
# print(ab2)
tmp = 0
for i in range(n):
    tmp += ab2[i][0]
if tmp > ab2[n-1][1]:
    print('No')
    exit()
print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [tuple(map(int,input().split())) for i in range(N)]
X = sorted(L, key = lambda k:k[1])
cnt = 0
ans = True
for i,j in X:
    cnt += i
    if cnt > j:
        ans = False
        print(cnt,j)
        break
        
if ans:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
lst=[0]*N
lst=[list(map(int,input().split())) for i in range(N)]
lst.sort
ans=0
t=0
for i in range(N):
 t+=lst[i][0]
 if t>lst[i][1]:
  ans+=1
if ans==0:
 print("Yes")
else:
 print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
AB =[]
total = 0
ans = "Yes"

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

for i in range(n):
  if total <= AB[i][1]:
    total += AB[i][0]
  else:
    ans = "No"
    break
    
if total > AB[n-1][1]:
  ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
AB =[]
total = 0
ans = "Yes"

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

for i in range(n):
  if total < AB[i][1]:
    total += AB[i][0]
  else:
    ans = "No"
    break
    
if total > AB[n-1][1]:
  ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
sortedab = sorted(ab, key=lambda x:x[1])
cleartime = [0]*n
cleartime[0] = sortedab[0][0]
flag = True
for i in range(n):
    cleartime[i] = cleartime[i-1] + sortedab[i][0]
    if cleartime[i] <= sortedab[i][1]:
        continue
    else:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
b = []
for i in range(n):
    x,y = map(int,input().split())
    b.append([y,x])
b.sort()
ans = 'Yes'
t = 0
for i in range(n):
    t += b[i][1]
    if t>b[i][0]:
        ans='No'
    print(t)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
B = []

for i in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if '{}'.format(b) in dic:
        dic['{}'.format(b)] += a
    else:
        dic['{}'.format(b)] = a

Bs = sorted(B)

time = 0

for i, num in enumerate(Bs):
    time += dic['{}'.format(num)]
    if num < time:
        print('No')
        break

    if i == len(Bs)-1:
        print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
B = []

for i in range(N):
    a, b = map(int,input().split())
    B.append(b)
    if '{}'.format(b) in dic:
        dic['{}'.format(b)] += a
    else:
        dic['{}'.format(b)] = a

Bs = sorted(B)

time = 0

for i, num in enumerate(Bs):
    time += dic['{}'.format(num)]
    if num < time:
        print('NO')
        break

    if i == len(Bs)-1:
        print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    task = []
    for _ in range(n):
        a, b = mi()
        task.append([a, b])
    task.sort(key=lambda x: x[1])
    t = max(task, key=lambda x: x[1])[1]
    while task:
        required_slot, end = task.pop()
        t -= required_slot
    print('No') if t < 0 else print('Yes')



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

ab = [[0]*2 for i in range(n)]

for i in range(n):
	ab[i][0], ab[i][1] = map(int, input().split())

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

print(ab)

ws = 0

for i in range(n):
	ws += ab[i][0]
	if ws > ab[i][1]:
		print('No')
		break
else:
	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])
ans = 0
for i in ab:
    ans+=i[0]
    if ans > i[1]:
        print(ans, i[0], i[1])
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

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

ans = 0
for i in ab:
    ans+=i[0]
    if ans > i[1]:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

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

prefix_cost = []
current_cost = 0
for i in range(N):
    current_cost += data[i][1]
    prefix_cost.append(current_cost)

for i in range(N):
    if not prefix_cost[i] <= data[i][0]:
        exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1]))
d=deque(data)
while(len(d)!=0):
    A,B=d.popleft()
    if B>=t:
        t+=A
    else:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1]))
d=deque(data)
final_task, final_time = d.pop()
while(len(d)!=0):
    A,B=d.popleft()
    if B>=t or t<final_time:
        t+=A
    else:
        print("No")
        exit()
t+=final_task
if t<=final_time:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1],x[0]))
d=deque(data)
final_task, final_time = d.pop()
while(len(d)!=0):
    A,B=d.popleft()
    if B<=t or t<final_time:
        t+=A
    else:
        print("No")
        exit()
t+=final_task
if t<=final_time:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1],x[0]))
d=deque(data)
final_task, final_time = d.pop()
while(len(d)!=0):
    A,B=d.popleft()
    if B<=t or t<=final_time:
        t+=A
    else:
        print("No")
        exit()
t+=final_task
if t<=final_time:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1]))
d=deque(data)
final_task, final_time = d.pop()
while(len(d)!=0):
    A,B=d.popleft()
    if B<=t or t<=final_time:
        t+=A
    else:
        print("No")
        exit()
t+=final_task
if t<=final_time:
    print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())

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

lst.sort(key=lambda tup: tup[1])
count = 0
for x in lst:
  if count > x[0]:
    print("No")
    exit()
  count += x[1]

print("Yes")

Submission status: Wrong Answer

Solution code:
x = int(input())
job = []
time = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append(j)
    time.append(t)
jt = 0
tt = 0
f = 0
for i in range(x):
    if job[i] <= time[i]:
        pass
    else:
        print("No")
        f = 1
        break
    jt += job[i]
    if tt < time[i]:
        tt = time[i]
    if jt > tt:
        f = 1
        print("No")
        break
if f == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
x = int(input())
job = []
time = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append(j)
    time.append(t)
jt = 0
tt = 0
f = 0
print(job, time)
for i in range(x):
    if job[i] <= time[i]:
        pass
    else:
        print("No")
        f = 1
        break
    jt += job[i]
    if tt < time[i]:
        tt = time[i]
    if jt > tt:
        f = 1
        print("No")
        break
if f == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
x = int(input())
job = []
time = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append(j)
    time.append(t)
jt = 0
tt = 0
f = 0
for i in range(x):
    if job[i] >= time[i]:
        pass
    else:
        print("No")
        f = 1
        break
    jt += job[i]
    if tt < time[i]:
        tt = time[i]
    if jt > tt:
        f = 1
        print("No")
        break
if f == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
x = int(input())
job = []
time = []
for i in range(x):
    j, t = list(map(int, input().split()))
    job.append(j)
    time.append(t)
jt = 0
tt = 0
f = 0
for i in range(x):
    jt += job[i]
    if tt < time[i]:
        tt = time[i]
    if jt > tt:
        f = 1
        print("No")
        break
if f == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = deque()
B = deque()
time = 0
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    time += a
    if time > B[i]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
A = deque()
B = deque()
time = 0
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    time += 0
    if time > B[i]:
        print("No")
        sys.exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

input = sys.stdin.readline
N = int(input())
A = deque()
B = deque() 
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

if sum(A) <= max(B):
    print("Yes")

else:
    print("No")

Submission status: Wrong Answer

Solution code:
# 締切の早いものから順番に見ていくのが最適戦略
N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]
X = sorted(X, key=lambda x: x[1])  # B (締切の早い順にソート)
diff = 0
for i in range(N):
    diff += X[i][1] - X[i][0]
    if diff < 0:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
ls = []
now = 0
simekiri = 0
flag = 0
for i in range(N):
    a,b = map(int,input().split())
    ls.append([b,a])
ls.sort()
print(ls)
for i in range(len(ls)):
    simekiri = ls[i][0]
    now += ls[i][1]
    if now > simekiri:
        print("No")
        flag += 1
        break
if flag == 0:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
from random import randint
input = sys.stdin.readline

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