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

Solution code:
n = int(input())

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

ans = 1
first = machines.pop(0)
stock_r = first[1]
for r,l in machines:
  if stock_r > l:
    break
  else:
    ans += 1
    stock_r = r

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

stock = []
stock.append(machines.pop(0))
for r,l in machines:
  if stock[-1][0] > l:
    break
  else:
    stock.append([r, l])

print(len(stock))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

stock = []
stock.append(machines.pop(0))
while len(machines) > 0:
  point = machines.pop(0)
  if stock[-1][1] > point[0]:
    continue
  else:
    stock.append(point)

print(len(stock))

Submission status: Wrong Answer

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0): # 四捨五入
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def round_up(a): # 切り上げ
    return int(a + 0.9)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    # arm[0] = right arm[1] = left
    arm = []
    for i in range(n):
        x,l = map(int,input().split())
        arm.append([min(x + l,100000),max(x - l,0)])
    arm.sort()
    r = 0
    ans = 0
    for i in range(n):
        if arm[i][1] > r:
            r = arm[i][0]
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0): # 四捨五入
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def round_up(a): # 切り上げ
    return int(a + 0.9)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    # arm[0] = right arm[1] = left
    arm = []
    for i in range(n):
        x,l = map(int,input().split())
        arm.append([min(x + l - 1,100000),max(x - l + 1,0)])
    arm.sort()
    r = 0
    ans = 0
    for i in range(n):
        if arm[i][1] > r:
            r = arm[i][0]
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0): # 四捨五入
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def round_up(a): # 切り上げ
    return int(a + 0.9)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    # arm[0] = right arm[1] = left
    arm = []
    for i in range(n):
        x,l = map(int,input().split())
        arm.append([min(x + l,100000),max(x - l,0)])
    arm.sort()
    r = 0
    ans = 0
    for i in range(n):
        if arm[i][1] >= r:
            r = arm[i][0]
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0): # 四捨五入
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def round_up(a): # 切り上げ
    return int(a + 0.9)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    # arm[0] = right arm[1] = left
    arm = []
    for i in range(n):
        x,l = map(int,input().split())
        arm.append([min(x + l - 1,100000),max(x - l + 1,0)])
    arm.sort()
    r = 0
    ans = 0
    for i in range(n):
        if arm[i][1] >= r:
            r = arm[i][0]
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
INF = 2 * (10 ** 9) - 1

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

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

cnt = 0
#print(xl)
cur = -10 ** 10
ans = 0

for i in range(n) :
    if cur <= xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
INF = 2 * (10 ** 9) - 1

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

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

cnt = 0
#print(xl)
cur = -10 ** 10
ans = 0

for i in range(n) :
    if cur < xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
INF = 2 * (10 ** 9) - 1

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

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

cnt = 0
#print(xl)
cur = -1
ans = 0

for i in range(n) :
    if cur < xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
INF = 2 * (10 ** 9) - 1

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l+1 if x-l+1 >= 0 else 0
    xl[i][1] = x+l-1 if x+l-1 <= INF else INF

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

cnt = 0
#print(xl)
cur = -1
ans = 0

for i in range(n) :
    if cur < xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
INF = 2 * (10 ** 9) - 1

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l+1 if x-l+1 >= 0 else 0
    xl[i][1] = x+l-1 if x+l-1 <= INF else INF

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

cnt = 0
print(xl)
cur = -1
ans = 0

for i in range(n) :
    if cur < xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))

X = np.array(X)
X = X[X[:,1].argsort(),:]
D = []
j = 0
for i in range(1,N):
    if (X[j,0] - X[j,1] +1 <= X[i,0] - X[i,1] +1) and (
        X[j,0] + X[j,1] -1  >= X[i,0] + X[i,1] -1):
      D.append(i)
      j -= 1
    j += 1

  
print(N - len(D))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))

X = np.array(X)
X = X[X[:,1].argsort(),:]
D = []
for i in range(1,N):
    if (X[i-1,0] - X[i-1,1] +1 <= X[i,0] - X[i,1] +1) and (
        X[i-1,0] + X[i-1,1] -1  >= X[i,0] + X[i,1] -1):
      D.append(i)

  
print(N - len(D))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))

X = np.array(X)
X = X[X[:,1].argsort(),:]
D = []
for i in range(1,N):
    if (X[i-1,0] - X[i-1,1] < X[i,0] - X[i,1]) and (
        X[i-1,0] + X[i-1,1] > X[i,0] + X[i,1]):
      D.append(i)

  
print(N - len(D))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))

min = min([x[0]-x[1] for x in X])
for i in range(N):
  X[i][0] = X[i][0] - min

max = int(max([x[0]+x[1] for x in X]))
X = np.array(X)
X = X[X[:,1].argsort(),:]

R = [0 for x in range(max)]
D = []
for i in range(N):
  for j in range(X[i][0] - X[i][1] + 1, X[i][0] + X[i][1]):
    if R[j] > 0:
      D.append(i)
      break
    else:
      R[j] += 1
      
print(N - len(D))

Submission status: Wrong Answer

Solution code:
def LR(x,l):
  return (x-l,x+l)
def overlap(a,b):
  return a[1]>=b[0]
if __name__=='__main__':
    N=int(input())
    XL=[]
    for i in range(N):
        xl=input().split()
        XL += [LR(int(xl[0]),int(xl[1]))]
    XL=sorted(XL,key=lambda x:x[0])
    result=[XL[0]]
    for i in range(1,N):
       last=result[-1]
       if not overlap(last,XL[i]):
          result+=[XL[i]]
    print(len(result))

Submission status: Wrong Answer

Solution code:
def LR(x,l):
  return (x-l,x+l)
def overlap(a,b):
  return a[1]>b[0]

if __name__=='__main__':
    N=int(input())
    XL=[]
    for i in range(N):
        xl=input().split()
        XL += [LR(int(xl[0]),int(xl[1]))]
    XL=sorted(XL,key=lambda x:x[0])
    result=[XL[0]]
    for i in range(1,N):
       last=result[-1]
       if not overlap(last,XL[i]):
          result+=[XL[i]]
    print(len(result))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = []
    xl = {}
    tmp = []
    ans = 0
    maxtmp = 0
    for i in range(n):
        xx, ll = map(int,input().split())
        if maxtmp < xx:
            maxtmp = xx
        low = xx-ll+1
        high = xx+ll-1
        lmh = [high,xx,low]
        tmp.append(lmh)


    tmp.sort()
    high = tmp[0][0]
    ans = 1
    for i in range(1,len(tmp)):
        a = tmp[i]
        if a[2] > high:
            high = a[0]
            ans += 1
        else:
            continue

    print(ans)
    return


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = []
    xl = {}
    tmp = []
    ans = 0
    maxtmp = 0
    for i in range(n):
        xx, ll = map(int,input().split())
        if maxtmp < xx:
            maxtmp = xx
        low = xx-ll+1
        high = xx+ll-1
        lmh = [low,xx,high]
        tmp.append(lmh)


    tmp.sort()
    high = tmp[0][2]
    ans = 1
    for i in range(1,len(tmp)):
        a = tmp[i]
        if a[0] > high:
            high = a[2]
            ans += 1
        else:
            continue

    print(ans)
    return


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = []
    xl = {}
    tmp = []
    ans = 0
    maxtmp = 0
    for i in range(n):
        xx, ll = map(int,input().split())
        if maxtmp < xx:
            maxtmp = xx
        low = xx-ll+1
        high = xx+ll-1
        lmh = [low,xx,high]
        tmp.append(lmh)


    tmp.sort()
    high = -1
    for i, a in enumerate(tmp):
        if a[0] > high:
            high = a[2]
            ans += 1
        else:
            continue

    print(ans)
    return


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
MAX_list = []
ans = 0
A = -10**9-2

for _ in range(N):
    X, L = map(int, input().split())
    MAX_list.append(((X + L ), (X - L )))
MAX_list = sorted(MAX_list)

for m, l in MAX_list:
    if l > A:
        ans += 1
        A = m

print(ans)

Submission status: Wrong Answer

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

n=int(readline())
m=map(int,read().split())
robots=list(zip(m,m))
robots.sort(key=lambda x:x[1])
prep=robots[0][1]
res=1
for l,r in robots[1:]:
  if l>=prep:
    res+=1
    prep=r
print(res)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    x = []
    xl = {}
    tmp = []
    ans = 0
    maxtmp = 0
    for i in range(n):
        xx, ll = map(int,input().split())
        if maxtmp < xx:
            maxtmp = xx
        low = max(xx-ll+1,0)
        high = xx+ll-1
        lmh = [low,xx,high]
        tmp.append(lmh)


    tmp.sort()
    high = -1
    for i, a in enumerate(tmp):
        if a[0] > high:
            high = a[2]
            ans += 1
        else:
            continue

    print(ans)
    return


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
INF = 10 ** 9

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l+1 if x-l+1 >= 0 else 0
    xl[i][1] = x+l-1 if x+l-1 <= INF else INF

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

cnt = 0
#print(xl)
cur = -1
ans = 0

for i in range(n) :
    if cur < xl[i][0] :
        #print(i)
        ans += 1
        cur = xl[i][1]
        #prinst(xl[i])


print(ans)

Submission status: Wrong Answer

Solution code:
INF = 10 ** 9

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l if x-l >= 0 else 0
    xl[i][1] = x+l if x+l <= INF else INF

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

cnt = 0
#print(xl)

for i in range(n-1) :
    if xl[i][1] >= xl[i+1][0] :
        #print(i)
        if xl[i][1] < xl[i+1][1] :
            xl[i+1][0] = xl[i][0]
            xl[i+1][1] = xl[i][1]
        cnt += 1

print(n-cnt)

Submission status: Wrong Answer

Solution code:
INF = 10 ** 9

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l if x-l >= 0 else 0
    xl[i][1] = x+l if x-l <= INF else INF

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

cnt = 0
#print(xl)

for i in range(n-1) :
    if xl[i][1] >= xl[i+1][0] :
        #print(i)
        if xl[i][1] < xl[i+1][1] :
            xl[i+1][0] = xl[i][0]
            xl[i+1][1] = xl[i][1]
        cnt += 1

print(n-cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[0]+x[1])

x, l = xl[0]
ans = n
for i in range(1, n):
    if x+l-1 < xl[i][0]-xl[i][1]+1:
        x, l = xl[i]
    else:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
INF = 10 ** 9

n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l+1 if x-l+1 >= 0 else 0
    xl[i][1] = x+l-1 if x-l+1 <= INF else INF

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

cnt = 0
#print(xl)

for i in range(n-1) :
    if xl[i][1] >= xl[i+1][0] :
        #print(i)
        if xl[i][1] < xl[i+1][1] :
            xl[i+1][0] = xl[i][0]
            xl[i+1][1] = xl[i][1]
        cnt += 1

print(n-cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[0]+x[1])

x, l = xl[0]
ans = n
for i in range(1, n):
    if x+l-1 <= xl[i][0]-xl[i][1]+1:
        x, l = xl[i]
    else:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[0]+x[1])

x, l = xl[0]
ans = n
for i in range(1, n):
    if x+l-1 <= xl[i][0]-xl[i][1]+1:
        x, l = xl[i]
    else:
        ans -= 1
print(xl)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [[0] * 2 for i in range(n)]
for i in range(n) :
    x, l = map(int, input().split())
    xl[i][0] = x-l+1
    xl[i][1] = x+l-1

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

cnt = 0
#print(xl)

for i in range(n-1) :
    if xl[i][1] >= xl[i+1][0] :
        #print(i)
        if xl[i][1] < xl[i+1][1] :
            xl[i+1][0] = xl[i][0]
            xl[i+1][1] = xl[i][1]
        cnt += 1

print(n-cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a =[]
for _ in range(n):
  
  a.append([int(i) for i in input().split()])
  
a.sort(key = lambda x : x[0])
#a.sort(key = lambda x : x[1])
#print(a)

curi = 0;curj=1
cnt=1
while(curj<n):
  if a[curi][0]+a[curi][1] <= a[curj][0]-a[curj][1]:
    curi=curj
    cnt+=1
  else: curi= min(curi,curj)
  curj+=1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[0]+x[1])

x, l = xl[0]
ans = n
for i in range(1, n):
    if l > xl[i][1]: 
        if (
            x-l+1 < xl[i][0]-xl[i][1] < x+l-1 or
            x-l+1 < xl[i][0]+xl[i][1] < x+l-1
            ):
                x, l = xl[i]
                ans -= 1
        else:
            x, l = xl[i]
    else:
        if (
            xl[i][0]-xl[i][1]+1 < x-l < xl[i][0]+xl[i][1]-1 or
            xl[i][0]-xl[i][1]+1 < x+l < xl[i][0]+xl[i][1]-1
            ):
                ans -= 1
        else:
            x, l = xl[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l+1, x-l-1))
    X.sort()
    ans = 1
    now = X[0][0]
    for i in range(1,N):
        b, a = X[i]
        if now +1< a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    lr = []
    for _ in range(N):
        p,l = map(int,input().split())
        lr.append((p-l,p+l))
        
    lr.sort(key = itemgetter(0,1))
    now = -10**10
    count = 0
    for i in range(N):
        if now <= lr[i][0]:
            count += 1
            now = lr[i][1]
        
    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    lr = []
    for _ in range(N):
        p,l = map(int,input().split())
        lr.append((p-l,p+l))
        
    lr.sort(key = itemgetter(0,1))
    print(lr)
    now = -10**10
    count = 0
    for i in range(N):
        if now <= lr[i][0]:
            count += 1
            now = lr[i][1]
        
    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    lr = []
    for _ in range(N):
        p,l = map(int,input().split())
        lr.append((p-l+1,p+l-1))
        
    lr.sort(key = itemgetter(0,1))
    now = -10**10
    count = 0
    for i in range(N):
        if now <= lr[i][0]:
            count += 1
            now = lr[i][1]
        
    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
rang=[]
for _ in range(N):
  x,l=map(int,input().split())
  rang.append((x-l, x+l))
rang=sorted(rang, key=lambda x: x[0])
lastright=rang[0][1]
cnt=1
for i in range(1,N):
  left=rang[i][0]
  right=rang[i][1]
  if left>=lastright:
    cnt+=1
    lastright=right
print(cnt)

Submission status: Wrong Answer

Solution code:
# Keyence B

N = int(input())
robot_list = []
robot_count = 0

for _ in range(N):
    x, l = map(int, input().split())
    robot_list.append([x - l, x + l])

robot_list.sort()
r = - 10**9 - 1

for i in range(N):
    if r <= robot_list[i][0]:
        robot_count += 1
        r = robot_list[i][1]

print(robot_count)

Submission status: Wrong Answer

Solution code:
### Keyence B

N = int(input())
robot_list = []
robot_count = 1

for _ in range(N):
    x, l = map(int, input().split())
    robot_list.append([x - l, x + l])

if N == 1:
    print(robot_count)
else:
    robot_list.sort()
    r = robot_list[0][1]
    
    for i in range(1, N):
        if r <= robot_list[i][0]:
            robot_count += 1
            r = robot_list[i][1]
    
    print(robot_count)

Submission status: Wrong Answer

Solution code:
N = int(input())

num_array = [[0]*2 for i in range(N)]
for i in range(N):
    x, l = map(int, input().split())
    small = x-l
    if small <= 0:
        small = 0
    big = x+l

    num_array[i][0] = small
    num_array[i][1] = big

num_array.sort()

tmp_r = -(10**18)
count = 0
for l, r in num_array:
    if tmp_r > l:
        continue
    count += 1
    tmp_r = r

print(count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
xl = []

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

xl = sorted(xl, key=itemgetter(0))

ans = 0
m = -float("inf")
for left, x, right in xl:
    if left < m:
        ans += 1
    else:
        m = max(m, right)

print(n - ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


num_array = [[0]*2 for i in range(N)]
for i in range(N):
    x, l = map(int, input().split())
    small = x-l
    if small <= 0:
        small = 0
    big = x+l

    num_array[i][0] = small
    num_array[i][1] = big

num_array.sort()

tmp = 0
flg = 0
for i in range(N-1):
    if flg == 1:
        flg = 0
        continue
    if num_array[i+1][0] < num_array[i][1]:
        tmp += 1
        flg = 1
        continue
print(N-tmp)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis=[]
count=0
for i in range(n):
    li=[None]*2
    x, l = map(int, input().split())
    li[0] = x+l
    li[1] = x-l
    lis.append(li)
lis.sort()
kari_r = -(10 ** 18)
print(lis)
for r, l in lis:
        if kari_r > l:
            continue
        count+=1
        kari_r = r
            
print(count)

Submission status: Wrong Answer

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

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

ans = 1
r = lr[0][1]
for i in range(1, n):
    if lr[i][0] < r < lr[i][1]:
        continue

    ans += 1
    r = lr[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li=[None]*2
lis=[]
count=0
for i in range(n):
    x, l = map(int, input().split())
    li[0] = x+l
    li[1] = x-l
    lis.append(li)
lis.sort()
kari_r = -(10 ** 18)
print(lis)
for r, l in lis:
        if kari_r > l:
            continue
        count+=1
        kari_r = r
            
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x-l+1, x+l-1))
    X = sorted(X, key = lambda x: x[1])
    ans = 1
    now = X[0][1]
    for i in range(1, N):
        a, b = X[i]
        if now < a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l-1, x-l+1))
    X.sort()
    ans = 1
    now = X[0][0]
    for i in range(1,N):
        b, a = X[i]
        if now < a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x-l+1, x+l-1))
    X.sort(reverse=True)
    ans = 0
    now = 10**10
    for i in range( N):
        a, b = X[i]
        if b <= now:
            now = a
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x-l+1, x+l-1))
    X.sort(reverse=True)
    ans = 0
    now = 10**10
    for i in range( N):
        a, b = X[i]
        if b < now:
            now = a
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
l = [0]*n
for i in range(n):
    x[i] , l[i] = map(int, input().split())
itv = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a = x[i]+l[i]
    b = x[i]-l[i]
    itv[i][0] = a
    itv[i][1] = b
itv.sort()

ans = 0
curx = -1000000000

for i in range(n):
    if curx <= itv[i][0]:
        curx = itv[i][1]
        ans += 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def main():
    N = int( input())
    X = []
    for _ in range(N):
        x, l = map( int, input().split())
        X.append((x+l-1, x-l+1))
    X.sort()
    ans = 0
    now = -10**9-1
    for i in range(N):
        b, a = X[i]
        if now < a:
            now = b
            ans += 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    lis = []
    for _ in range(n):
        x, l = LI()
        lis.append((x + l, x - l))
    lis.sort()
    ans = 0
    now = 0
    for r, l in lis:
        if now <= l:
            now = r
            ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# Keyence B

N = int(input())
robot_list = []
robot_count = 1

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

if N == 1:
    print(N)
else:
    robot_list.sort()
    r = robot_list[0][0] + robot_list[0][1]
    
    for i in range(1, N):
        if r <= robot_list[i][0] - robot_list[i][1]:
            robot_count += 1
            r = robot_list[i][0] + robot_list[i][1]
    
    print(robot_count)