Problem:


Score : 200 points

Problem Statement

In a factory, there are N robots placed on a number line.
Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative.

We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect.
Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints.

Find the maximum number of robots that we can keep.

Constraints

1 \leq N \leq 100,000

0 \leq X_i \leq 10^9 (1 \leq i \leq N)

1 \leq L_i \leq 10^9 (1 \leq i \leq N)

If i \neq j, X_i \neq X_j.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 L_1
X_2 L_2
\vdots
X_N L_N

Output

Print the maximum number of robots that we can keep.

Sample Input 1

4
2 4
4 3
9 3
100 5

Sample Output 1

3

By removing Robot 2, we can keep the other three robots.

Sample Input 2

2
8 20
1 10

Sample Output 2

1

Sample Input 3

5
10 1
2 1
4 1
6 1
8 1

Sample Output 3

5



Sample input:
4
2 4
4 3
9 3
100 5


Sample output:
3

Submission status: Runtime Error

Solution code:
n= int(raw_input())
d = {}
for i in range(n):

	r, l= raw_input().split(" ")
	d[int(r)] = int(l)
    
s = []
for i in sorted(d.keys()) :  
     s.append([i,d[i]]) 
t=0
popped = 0
for i in s:
  x_current = s[t][0]
  x_next = s[t+1][0]
  l_current = s[t][1]
  l_next = s[t+1][1]
  
  if (x_current + l_current) > (x_next - l_next):
    # current interserts with next
    # pop next
    popped += 1
    t+=1
  t +=1
  if t >= len(s)-1:
    break

print(len(s)-popped)

Submission status: Runtime Error

Solution code:
def isValid(area_A, area_B):
  flag = True
  if area_A[0] < area_B[0] < area_A[1]:
    flag = False
  elif area_A[0] < area_B[1] < area_A[1]:
    flag = False
  return flag 

N = int(input())
Xs = {}
Ls = []
for _ in range(N):
  X, L = map(int, input().split(' '))
  Xs[X] = L
sorted_Xs = sorted(Xs.keys())
tmp = sorted_Xs[:]

areas = [(X-Xs[X], X+Xs[X]) for X in sorted_Xs]
counts = [0 for _ in range(len(sorted_Xs))]
finished = 1
while (finished):
  areas = [(X-Xs[X], X+Xs[X]) for X in tmp]
  for i, area_A in enumerate(areas):
    for j, area_B in enumerate(areas):
      if not isValid(area_A, area_B):
        count += 1
    counts[i] = count
  finished = sum(counts)
  if finished:
  	tmp.pop( tmp.index(max(tmp)) )
  
print(len(tmp))

Submission status: Runtime Error

Solution code:
N = int(input())


XList = []
LList = []

for i in range(0, N):
    X, L = map(int, input().split())
    XList.append(X)
    LList.append(L)

TMP = zip(XList, LList)
tmp = sorted(TMP)
XList, LList = zip(*tmp)
XList = list(XList)
LList = list(LList)

for i in range(0, N):
    for q in range(i + 1, N):
        

        if XList[i] + LList[i] > XList[q] - LList[q]:
            XList.pop(q)
            LList.pop(q)
            q -= 1
            N -= 1
        else:
            break
        
print(len(XList))

Submission status: Runtime Error

Solution code:
n = int(input())
box = [0]*10**5
for i in range(n):
  x, l = map(int, input().split())
  a = x-l
  if a<0:
    a = -1
  b = x+l
  c = [1]*(b-a-1)
  box[a+1:b] = [x + y for (x, y) in zip(box[a+1:b],c)]
print(n-(max(box)-1))

Submission status: Runtime Error

Solution code:
import numpy as np

def find_dex(list,dex):
    for j in range(len(list)):
        if list[j][0] == dex:
            return j

    return 0

n = int(input())
a = np.zeros((10**9))
d = []
left = []
right = []
for i in range(n):
    x,l = map(int, input().split())
    # num , left , right
    left.append([i,x-l+1,x+l-1])
    right.append([i,x-l+1,x+l-1])

left.sort(key=lambda x:x[1],reverse=False)
right.sort(key=lambda x:x[2],reverse=False)

flag = True
p = 10**9 + 1
ans = 0
while len(left) > 0:
    if flag:
        i,l,r = left.pop(-1)
        right.pop(find_dex(right,i))
        flag = False
        if r >= p:
            ans += 1
        p = l

    else:
        i,l,r = right.pop(-1)
        left.pop(find_dex(left,i))
        flag = True
        if r >= p:
            ans += 1
        p = l


    #print(i,l,r)
    #print(left)
    #print(right)

print(n-ans)

Submission status: Runtime Error

Solution code:
n = int(input())
box = [0]*120
for i in range(n):
  x, l = map(int, input().split())
  a = x-l
  if a<0:
    a = -1
  b = x+l
  c = [1]*(b-a-1)
  box[a+1:b] = [x + y for (x, y) in zip(box[a+1:b],c)]
print(n-(max(box)-1))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)
from functools import lru_cache


def resolve():
    global N, grid

    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    grid = [[int(x) for x in sys.stdin.readline().split()]
            for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    print(dp((), 0))


def canPut(filled, x, l):
    if filled == ():
        return True
    return all([right <= x - l or x + l <= left for (left, right) in filled])


def dp(filled, i):
    if i == N - 1:
        if canPut(filled, *grid[i]):
            return 1
        else:
            return 0

    n_ex = dp(filled, i + 1)
    n_in = 0
    if canPut(filled, *grid[i]):
        x, l = grid[i]
        n_in = dp(tuple([*filled, (x - l, x + l)]), i + 1) + 1

    return max([n_ex, n_in])


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 4
4 3
9 3
100 5"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
8 20
1 10"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
10 1
2 1
4 1
6 1
8 1"""
        output = """5"""
        self.assertIO(input, output)

Submission status: Runtime Error

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

a=[0]*n
b=[0]*n

for i in range(n):
    a[i],b[i]=x[i]-l[i],x[i]+l[i]
    
cnt=0    
while(b):
    bm=min(b)
    a.pop(b.index(min(b)))
    b.pop(b.index(min(b)))
    cnt+=1
    for j in range(len(a)):
        if a[j]<bm:
            a.pop(j)
            b.pop(j)

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())

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

riList = []
leList = []
for i in range(n):
  riList.append(rList[i][0]-rList[i][1])
  leList.append(rList[i][0]+rList[i][1])

riList = sorted(riList)
leList = sorted(leList)

i =0
j =1 
count = 0
while True:
  if riList[j] < leList[i]:
    count += 1
    j += 1
  else:
    i=j
    j+=1
  
  if j >= len(leList)-1:
    break

print(n-count)

Submission status: Runtime Error

Solution code:
N = int(input())
x_l = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    x_l.append(array)

x_l.sort()

for i in range(0,N-2):
  if (x_l[i][0] + x_l[i][1]) > (x_l[i+1][0] - x_l[i+1][1]):
    del x_l[i+1]

print(len(x_l))

Submission status: Runtime Error

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

lr = []
lim = 0
for i in range(n):
    l = max(xl[i][0] - xl[i][1], 0)
    r = max(xl[i][0] + xl[i][1], 0)
    lim = max(lim, l, r)
    lr.append([l, r])

memo = [0] * lim

remove = 0
for i in range(n):
    for j in range(lr[i][0], lr[i][1]):
        if memo[j] == 1:
            remove += 1
            break
        else:
            memo[j] = 1

print(n - remove)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())

    x = []
    l = []
    tls = []
    for i in range(n):
        tmp = list(map(int, input().split()))
        x.append(tmp[0])
        l.append(tmp[1])
    x, l = zip(*sorted(zip(x, l)))

    m = {}
    def solve(prev, idx):
        if idx == n:
            return 0
        key = (prev, idx)
        if key in m:
            return m[key]
        res_use = 0
        res_nouse = 0

        if x[idx] - l[idx] >= prev or prev == 0:
            res_use = 1
            res_use += solve(x[idx] + l[idx], idx + 1)
        res_nouse += solve(prev, idx + 1)

        ans = max(res_use, res_nouse)
        m[key] = ans
        return ans
    print(solve(0, 0))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input().rstrip())
robos = []
max = 0

for i in range(n):
    line = input().rstrip().split(' ')
    array = [int(line[0]), int(line[1])]
    robos.append(array)
    if max < array[0] + array[1] - 1:
        max = array[0] + array[1] - 1

field = [0] * max
count = 0
for item in robos:
    countFlg = True
    for i in range(item[0] - item[1] + 1, item[0] + item[1] - 1):
        if i < 0:
            continue
        if field[i] == 0:
            field[i] = 1
        else:
            countFlg = False
            break
    if countFlg == True:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
x_l = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    x_l.append(array)

x_l.sort()

for i in range(0,N-1):
  if (x_l[i][0] + x_l[i][1]) > (x_l[i+1][0] - x_l[i+1][1]):
    del x_l[i+1]

print(len(x_l))

Submission status: Runtime Error

Solution code:
N = int(input())
num_list = [[int(item) for item in input().split()] for _ in range(N)]
num_list.sort(key=lambda x: x[0]) 
# print(num_list)

temp_max = num_list[0][0] + num_list[0][1]
cnt = 1

for x, l in num_list:
    if x - l >= temp_max:
        cnt += 1
        temp_max = x + l
        # print(x, l, cnt, temp_max)


temp_max2 = num_list[1][0] + num_list[1][1]
cnt2 = 1

for x, l in num_list[1:]:
    if x - l >= temp_max2:
        cnt2 += 1
        temp_max2 = x + l
        # print(x, l, cnt, temp_max)

if cnt2 > cnt:
    cnt, cnt2 = cnt2, cnt
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
xl = [list(map(int,input().split())) for i in range(n)]
xl.sort()
def OK(list):
  for i in range(n-1):
    if list[i][0]+list[i][1] > list[i+1][0]-list[i+1][1]:
      return False
  return True

while OK(xl)==False:
  r=len(xl)
  memo=[0]*r
  for i in range(r-1):
    if memo[i]==0 and xl[i][0]+xl[i][1]>xl[i+1][0]-xl[i+1][1]:
      memo[i+1] += 1
  for i in range(r):
    if memo[r-1-i]==1:
      del xl[r-1-i]
print(len(xl))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[0])

    i = 0
    while True:
        if ranges[i][1] > ranges[i + 1][0]:
            ranges.pop(i + 1)
        else:
            i += 1
        if i == len(ranges) - 1:
            break
    print(len(ranges))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n= int(raw_input())
d = {}
for i in range(n):

	r, l= raw_input().split(" ")
	d[int(r)] = int(l)
    
s = []
for i in sorted(d.keys()) :  
     s.append([i,d[i]]) 
t=0
popped = 0
for i in s:
  x_current = s[t][0]
  x_next = s[t+1][0]
  l_current = s[t][1]
  l_next = s[t+1][1]
  
  if (x_current + l_current) > (x_next - l_next):
    # current interserts with next
    # pop next
    popped += 1
    t+=1
  t +=1
  if t >= len(s)-2:
    break

print(len(s)-popped)

Submission status: Runtime Error

Solution code:
n = int(input())

xl = []
for i in range(n):
    x, l = map(int, input().split())
    xl.append([x-l+1, x+l-1])


print(xl)
ans = []
p = len(xl) - 1

i = 0
while(i < p):
    if (xl[i][1] > xl[i + 1][0]):
        ans += 1
        xl.pop(i + 1)
        p -= 1
    else:
        i += 1
# print(xl)

print(n-ans)

Submission status: Runtime Error

Solution code:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    N=I()
    s = []
    for i in range(N):
        x,l=MI()
        s.append([x,l])
    s.sort(key=lambda x:x[0])
    p=[]    
    for i in range(N):
        x,l=s[i]
        p.append([x-l,x+l])
    # print(p)
    prev=p[0]
    c=0
    for i in range(1,N):
        # print(p[i][0],prev[1])
        if p[i][0]<prev[1]:
            c+=1
        else:
            prev=p[i]
    prev=p[-1]
    c1=0
    for i in range(n-2,-1,-1):
        # print(p[i][0],prev[1])
        if p[i][0]<prev[1]:
            c1+=1
        else:
            prev=p[i]
    print(max(N-c,N-c1))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())

x = []
l = []
tls = []
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp[0])
    l.append(tmp[1])
x, l = zip(*sorted(zip(x, l)))

m = {}
def solve(prev, idx):
    if idx == n:
        return 0
    key = (prev, idx)
    if key in m:
        return m[key]
    res_use = 0
    res_nouse = 0

    if x[idx] - l[idx] >= prev or prev == 0:
        res_use = 1
        res_use += solve(x[idx] + l[idx], idx + 1)
    res_nouse += solve(prev, idx + 1)

    ans = max(res_use, res_nouse)
    m[key] = ans
    return ans
print(solve(0, 0))

Submission status: Runtime Error

Solution code:
n = int(input())

x = []
l = []
tls = []
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp[0])
    l.append(tmp[1])
x, l = zip(*sorted(zip(x, l)))

m = {}
def solve(prev, idx):
    if idx == n:
        return 0
    key = (prev, idx)
    if key in m:
        return m[key]
    res_use = 0
    res_nouse = 0

    if x[idx] - l[idx] >= prev or prev == 0:
        res_use = 1
        res_use += solve(x[idx] + l[idx], idx + 1)
    res_nouse += solve(prev, idx + 1)

    ans = max(res_use, res_nouse)
    m[key] = ans
    return ans
print(solve(0, 0))

Submission status: Runtime Error

Solution code:
ranges = []
for n in range(int(input())):
    x, l = list(map(int, input().split()))
    ranges.append([x-l, x+l])

ranges.sort()

if (len(ranges) == 1):
    print(1)

elif (len(ranges) == 2):
    if (ranges[1][0] < ranges[0][1]):
        print(1)
    else:
        print(2)

else:
    corr = [0 for i in range(n+1)]
    temp = []

    while True:
        
        l = len(ranges)
        
        for i in range(l-1):
            if (ranges[i+1][0] < ranges[i][1]):
                if (ranges[i+2][0] < ranges[i+1][1]):
                    corr[i+1] = 1
                    ranges[i+1] = ranges[i]
                else:
                    corr[i] = 1
                    if (i != 0):
                        ranges[i] = ranges[i-1]

        if (set(corr)) == {0}:
            break
        
        for i in range(l):
            if (corr[i] == 1):
                pass
            else:
                temp.append(ranges[i])

        ranges = list(temp)
        temp = []
        corr = [0 for i in range(len(ranges))]

    print(len(corr))

Submission status: Runtime Error

Solution code:
n = int(input())

line = []
ans = 0

for i in range(n):
  x, l = map(int, input().split())
  keep = True
  for j in range(x-l+1, x+l):
    if j in line:
      keep = False
    else:
      line.append(j)
  print(keep)
  if keep == True:
    ans += 1
  else:

print(ans)

Submission status: Runtime Error

Solution code:
    def main():
        N = int(input())
        X = []
        L = []
        for i in range(N):
            x, l = [int(s) for s in input().split()]
            X.append(x)
            L.append(l)
     
        ranges = []
        for i in range(N):
            ranges.append((X[i] - L[i], X[i] + L[i]))
        ranges.sort(key=lambda x: x[0])
     
        while True:
            dup = [0 for i in range(len(ranges))]
            for i in range(len(ranges) - 1):
                if ranges[i][1] > ranges[i + 1][0]:
                    dup[i] += 1
                    dup[i + 1] += 1
     
            remove_index = [(i, dup[i]) for i in range(len(dup))]
            remove_index.sort(key=lambda x: x[1], reverse=True)
            if remove_index[0][1] == 0:
                break
            ranges.pop(remove_index[0][0])
        print(len(ranges))
     
     
    if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
n,k,s = [int(i) for i in input().split()]

for i in range(k):
    print(s,end="")
    if i!=k-1:
        print(" ",end="")

s = s-1 if s==10**0 else s+1

for i in range(k,n):
    print(" "+str(s),end="")

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))
for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
XL = []
for n in range(N):
    XL.append([int(x) for x in input().split()])
XL = sorted(XL, key=lambda x:x[1])
s = np.zeros(2*(10**9))
ans = 0
for n in range(N):
    a = s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]]
    if max(a) != 0:
        ans += 1
    else:
        s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]] += 1
print(N-ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
XL = []
for n in range(N):
	XL.append([int(x) for x in input().split()])
XL = sorted(XL, key=lambda x:x[1])
s = np.zeros(2*(10**9))
ans = 0
for n in range(N):
	a = s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]]
	if a.max() != 0:
		ans += 1
	else:
		s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]] += 1
print(N-ans)

Submission status: Runtime Error

Solution code:
n = int(input())

x = []
l = []
for i in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp[0])
    l.append(tmp[1])
keydict = dict(zip(l, x))
l.sort(key=keydict.get)
x.sort()

m = {}
def solve(prev, idx):
    if idx == n:
        return 0
    key = (prev, idx)
    if key in m:
        return m[key]
    res_use = 0
    res_nouse = 0

    if x[idx] - l[idx] >= prev or prev == 0:
        res_use = 1
        res_use += solve(x[idx] + l[idx], idx + 1)
    res_nouse += solve(prev, idx + 1)

    ans = max(res_use, res_nouse)
    m[key] = ans
    return ans
print(solve(0, 0))

Submission status: Runtime Error

Solution code:
N = int(input())
x_l = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    x_l.append(array)

x_l.sort()

for i in range(N-1):
  if (x_l[i][0] + x_l[i][1]) > (x_l[i+1][0] - x_l[i+1][1]):
    del x_l[i+1]

print(len(x_l))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
XL = []
for n in range(N):
    XL.append([int(x) for x in input().split()])
XL = sorted(XL, key=lambda x:x[1])
s = np.zeros(2*(10**9))
ans = 0
for n in range(N):
    a = s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]]
    if a.max() != 0:
        ans += 1
    else:
        s[max(XL[n][0]-XL[n][1],-1)+1:XL[n][0]+XL[n][1]] += 1
print(N-ans)

Submission status: Runtime Error

Solution code:
n = int(input())
x, l = [0]*n, [0]*n
box = [0]*10**9
for i in range(n):
  x[i], l[i] = map(int, input().split())
  a = x-l
  b = x+l
  box[a+1:b]=[1]
  print(box)

Submission status: Runtime Error

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

data = sorted(data)
end1 = -1000000000000
end2 = data[1][0]
ans1 = 0
ans2 = 0
for i in data:
    if(i[0] >= end1):
        ans1+=1
        end1 = i[1]

    if(i[0] >= end2):
        ans2+=1
        end2 = i[1]

print(max(ans1, ans2))

Submission status: Runtime Error

Solution code:
N = int(input())

XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append((x, l))
XL.sort()
#print(XL)

import sys
sys.setrecursionlimit(2000)
    
def dfs(right, idx, num):
    if idx == N:
        return num
    
    new_right = XL[idx][0] + XL[idx][1]
    new_left = XL[idx][0] - XL[idx][1]
    
    if right > new_left:
        return dfs(right, idx+1, num)
    else:
        return max(dfs(right, idx+1, num), dfs(new_right, idx+1, num+1))
    
ans = dfs(-1*10**9-1, 0, 0)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append((x, l))
XL.sort()
#print(XL)

    
def dfs(right, idx, num):
    if idx == N:
        return num
    
    new_right = XL[idx][0] + XL[idx][1]
    new_left = XL[idx][0] - XL[idx][1]
    
    if right > new_left:
        return dfs(right, idx+1, num)
    else:
        return max(dfs(right, idx+1, num), dfs(new_right, idx+1, num+1))
    
ans = dfs(-1*10**9-1, 0, 0)
print(ans)

Submission status: Runtime Error

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

prev_right = -float("inf")
ans = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

xl = reversed(xl)

prev_right = -float("inf")
ans_ = 0
for i in range(n):
    now_left = xl[i][0] - xl[i][1]
    if prev_right > now_left:
        ans_ += 1
    else:
        prev_right = xl[i][0] + xl[i][1]

print(n - min(ans, ans_))

Submission status: Runtime Error

Solution code:
h = int(input())
w = int(input())
n = int(input())

decr = max(h,w)

ans = 1
for i in range(min(h,w)):
    n -= decr
    if n <=0:
        print(ans)
        exit()
    ans += 1
print(ans)

Submission status: Runtime Error

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

cnt = n
j = 0
for i in range(n):
    if x[j][0] + x[j][1] > x[j + 1][0] - x[j][1]:
        cnt -= 1
        j += 1
    j += 1
    if j >= n - 1:
        break
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
ans=0
xl.sort()
if xl[0][0]+xl[0][1]>xl[1][0]-xl[1][1]:
    xl[1][0]=-1
    ans+=1

for i in range(1,n-1):
    if xl[i][0]==-1:
        continue
    else:
        if xl[i][0]+xl[i][1]>xl[i+1][0]-xl[i+1][1]:
            ans+=1
            xl[i+1][0]=-1
# print(xl)
print(n-ans)

Submission status: Runtime Error

Solution code:
n=int(input())
d=sorted([list(map(int,input().split()))for i in range(n)],key=lambdax:x[0]+x[1])
c=-float("INF")
an=0
for i,j in d:
    if i-j>=c:
        an+=1
        c=i+j
print(an)