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())
dic = {}

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

dic = sorted(dic.items())
pre = dic[0][0]+dic[0][1]
ans = 1

for i in range(n-1):
    if pre <= dic[i+1][0]-dic[i+1][1]:
        pre = dic[i+1][0]+dic[i+1][1]
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 10000000000 * student[0] + student[1])

now = -100000000000
ans = 0
for i in fanwei:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]

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



li=[0 for i in range(n)]
li1=[[] for i in range(n)]
for i in range(len(x)):
    for j in range(i+1,len(x)):
        if x[j][0]<x[i][1]<x[j][1] or x[j][0]<x[i][0]<x[j][1]:
            li[i]+=1
            li[j]+=1
            li1[i].append(j)
            li1[j].append(i)
            
count=0
while sum(li)!=0:
    pp=li.index(max(li))
    li[pp]=0
    for i in li1[pp]:
        li[i]-=1
        
    
    
    count+=1

print(n-count)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [[0, 0] for i in range(n)]
for i in range(n):
  xl[i] = list(map(int, input().split()))
xl.sort(key=lambda x:x[0])
haji = xl[0][0] + xl[0][1]
puted = 1
for i in range(1, n):
  if haji <= xl[i][0] - xl[i][1]:
    puted += 1
    haji = xl[i][0] + xl[i][1]
print(puted)

Submission status: Wrong Answer

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

X_ = list(map(lambda p: p[0], XL))
indices = sorted(range(len(X_)), key=lambda k: X_[k])
XL = [XL[i] for i in indices]

for i, (x, l) in enumerate(XL):
    if i == 0 or i == len(XL)-1:
        continue
    if XL[i+1][0] - XL[i+1][1] < x + l and x-l < XL[i-1][0] + XL[i-1][1]:
        XL.pop(i)
for i, (x, l) in enumerate(XL):
    if i == 0 or i == len(XL)-1:
        continue
    if XL[i+1][0] - XL[i+1][1] < x + l or x-l < XL[i-1][0] + XL[i-1][1]:
        XL.pop(i)

print(len(XL))

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: (x[0]+x[1],-x[0]+x[1]))
M = XL[0][0]+XL[0][1]-1
ans = N
for i in range(1,N):
    if M >= XL[i][0]-XL[i][1]+1:
        ans -= 1
    else:
        M = XL[i][0]+XL[i][1]-1
print(ans)

Submission status: Wrong Answer

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]
    print(N-c)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
List=[]
a,b=(int(x) for x in input().split())
List.append([a,a-b,a+b])

for i in range(N-1):
    a,b=(int(x) for x in input().split())
    minimum=a-b
    maximam=a+b
    flag=False
    for j in List:
        if(j[1]<minimum and minimum<j[2]):
            flag=True
            break
        elif(j[1]<maximam and maximam<j[2]):
            flag=True
            break
    if(flag==False):
        List.append([a,a-b,a+b])

print(len(List))

Submission status: Wrong Answer

Solution code:
N = int(input())

xl = []

for i in range(N):
    xl.append(list(map(int,input().split())))

xl.sort()



left = [0]*N
right = [0]*N
exist = [1]*N

for i in range(N):
    left[i] = xl[i][0] - xl[i][1] + 1
    right[i] = xl[i][0] + xl[i][1] - 1

most_right = 0
for i in range(N-1):
    tmp = right[most_right]
    if exist[i]:
        if tmp >= left[i+1]:
            exist[i] = 0
        else:
            most_right += 1
print(sum(exist))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
ans = 0
x = [0] * n
for i in range(n):
    x[i] = tuple([int(x) for x in input().strip().split()])

x.sort()
pre = -float('inf')
for xx in x:
    if pre > xx[0] - xx[1]:
        if pre < xx[0] + xx[1]:
            continue
        else:
            pre = xx[0] + xx[1]
    
    ans += 1
    pre = xx[0] + xx[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
N=int(input())
XL = [list(map(int,input().split())) for i in range(N)]
XL.sort()

ans=0
i=0
while i<N-1:
  j=1
  while True:
    a_2=XL[i][0]+XL[i][1]
    b_1=XL[i+j][0]-XL[i+j][1]
    if a_2>b_1:
      ans+=1
      j+=1
      if i+j==N:
        break
    else:
      break
  i+=j
  
print(N-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xs = []
scope = {}
for _ in range(n):
    x, l = map(int, input().split())
    xs.append(x)
    scope[x] = [x-l, x+l]
    
xs.sort()
ans = 1
end = scope[xs[0]][1]
for i in xs:
    start = scope[i][0]
    if end <= start:
        ans += 1
        end = start
print(ans)

Submission status: Wrong Answer

Solution code:
H = int(input())

_list = []

for i in range(H):
  set = input().split(" ")
  _list.append([int(set[0]), int(set[1])])

new_list = sorted(_list)

ans_list = [new_list[0]]
for i in new_list:
  arm_long = ans_list[-1][0] + ans_list[-1][1] -1
  arm_short = i[0] - i[1] +1
  if arm_long < arm_short:
    ans_list.append(i)
print(len(ans_list))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    li = []
    for _ in range(N):
        a,b = [int(n) for n in input().split()]
        li.append([a-b+1,a+b-1])
    li.sort(key=lambda x:x[0])
    last = (-10**10,-10**10)
    res = N
    for a in li:
        if last[1] > a[1]:
            last = a
            res-=1
        elif last[1] > a[0]:
            last = last
            res-=1
        elif last[1] <= a[0]:
            last = a
    print(res)

main()

Submission status: Wrong Answer

Solution code:
n = int(input())

datas = [list(map(int, input().split())) for _ in range(n)]
ans = [datas[0]]
count = True

for i in datas[1::]:
    count = True
    for j in ans:
        if j[0] - j[1] < i[0] - i[1] < j[0] + j[1]:
            count = False

        elif j[0] - j[1] < i[0] + i[1] < j[0] + j[1]:
            count = False

        elif j[0] - j[1] < i[0] < j[0] + j[1]:
            count = False

    if count:
        ans.append(i)

print(len(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
X_L = sorted([list(map(int,input().split())) for _ in range(N)])
flag = 0
count = 0

for i in range(N-1):
    if flag == 0:
        if X_L[i][0]+X_L[i][1] > X_L[i+1][0]-X_L[i+1][1]:
            flag = 1
            count += 1
print(N-count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
N = int(input())
robot_list = []

for i in range(N):
    robot_list.append(list(map(int, input().split())))
    robot_list[i] = (robot_list[i][0] - robot_list[i][1] + 1, robot_list[i][0] + robot_list[i][1] - 1, robot_list[i][0], robot_list[i][1])

sort_robot_list = sorted(robot_list, key=itemgetter(2))

minus_count = 0
for before_value, after_value in zip(sort_robot_list, sort_robot_list[1:]):
    if before_value[1] > after_value[0]:
        minus_count += 1

print(len(sort_robot_list) - minus_count)

Submission status: Wrong Answer

Solution code:
n=int(input())
xl=[list(map(int,input().split())) for _ in range(n)]
xl.sort(key=lambda x: x[0])
ans=1
nx,nl=xl[0]
for i in range(1,n):
  x,l=xl[i]
  if nx+nl<=x-l:
    ans+=1
    nx=x
    nl=l
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
xl=sorted([[int(i) for i in input().split()] for _ in range(n)],key=lambda x:x[0])
check=[True]*n
i=1
left=0
right=1
count=0
while(i<n):
    if xl[left][0]-xl[left][1]<xl[right][0]<xl[left][0]+xl[left][1]:
        right+=1
        i+=2
        count+=1
    else:
        left+=1
        right+=1
        i+=1
print(n-count)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
XL = sorted([list(map(int, input().split())) for _ in range(n)], key=itemgetter(0))
i = 1
while i != len(XL):
    if XL[i][0] - XL[i-1][0] > XL[i][1] + XL[i][1]:
        XL.pop(i)
    else:
        i += 1

print(len(XL))

Submission status: Wrong Answer

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


def solve(N: int, X: "List[int]", L: "List[int]"):
    d = {}
    for i in range(N):
        d[X[i]]=L[i]

    d=sorted(d.items())

    maeR=d[0][0]+d[0][1]

    toru=0
    for i in range(1,N):
        tsugiL=d[i][0]-d[i][1]
        if maeR>tsugiL:
            toru+=1
        else:
            maeR=d[i][0]+d[i][1]

    print(N-toru)
    
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
X = []
L = []
for _ in range(N):
    row = list(map(int,input().split()))
    X.append(row[0])
    L.append(row[1])

# Xでソート
c = list(zip(X, L))
c.sort(key=itemgetter(0))
X, L = zip(*c)

# stack
stack = []
stack.append(0)
# 2~N番を，それ以前と重複しなければpush
for i in range(1,N):
    X1 = X[stack[-1]]
    L1 = L[stack[-1]]
    X2 = X[i]
    L2 = L[i]
    # 重複しなければ
    # print(X1+L1,X2-L2)
    if X1+L1 <= X2-L2:
        stack.append(i)            


print(len(stack))

Submission status: Wrong Answer

Solution code:
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x, l))

robots = sorted(robots, key=lambda x: x[0])
# print(robots)
rightest_point = robots[0][0] + robots[0][1] - 1

ans = 0
for i in range(1, N):
    if robots[i][0]-robots[i][1]+1 <= rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1

print(N-ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = [[]]*n
for i in range(n):
    x, l = map(int, input().split())
    data[i] = [x-l,x+l]
data.sort()
ans = n
if len(data) > 3:
    if data[0][1] > data[2][0]:
        data[0][1] = 0
    if data[n-3][1] > data[n-1][0]:
        data[n-1][0] = 10**9


for i in range(1, n-1):
    if data[i-1][1] > data[i][0] and data[i][1] > data[i+1][0]:
        ans -= 1

print(ans)

Submission status: Wrong Answer

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

n = int(input())
X = []
L = []
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append( (a-b, a+b) )
    X.append(a)
    L.append(b)

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

ans = 1
cur = T[0][0]
for k, v in enumerate(T):
    if k == 0: continue
    if v[1] <= cur:
        ans += 1
        cur = T[k][0]

print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 10000000000 * student[0] + student[1])


now = -100000000000
ans = 0
for i in fanwei:
    down = i[0] - i[1]
    if down >= now:
        ans += 1
        now = i[0] + i[1]

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
s = [i[0]-i[1]+1 for i in a]
t = [i[0]+i[1]-1 for i in a]

st = sorted([(s[i], t[i]) for i in range(n)], key=itemgetter(1))
ans = 0
last = -10**9

for i in range(n):
    if last < st[i][0]:
        ans += 1
        last = st[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
ab=[]
for i in range(n):
    x=xl[i][0]
    l=xl[i][1]
    a=x-l
    b=x+l
    ab.append([a,b])
ab.sort(key=lambda x:x[1])
A=ab[-1][0]
B=ab[-1][1]
cnt=1
for i in range(n-1):
    a=ab[-i-2][0]
    b=ab[-i-2][1]
    if b<=A:
        cnt+=1
        A=a
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
r.sort()

ans = N
i = 1
while i < N:
    x1, l1 = r[i-1]
    x2, l2 = r[i]
    if (x1+l1) > (x2-l2):
        i += 1
        ans -= 1
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())

left = np.zeros(n)
right = np.zeros(n)
for i in range(n):
    x, l = map(int, input().split())
    left[i] = x-l
    right[i] = x+l

sort_ind = np.argsort(right)
left = left[sort_ind]
right = right[sort_ind]

ans = 0
right_now = -1
for i in range(n):
    if(left[i] >= right_now):
        ans += 1
        right_now = right[i]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

robots = []

for i in range(N):
  x, l = [int(v) for v in input().split()]
  
  robots.append((x - l, x + l))

robots.sort()

def check(robot):
  for i in range(1, N):
    if robot[i-1][1] > robot[i][0]:
      return False
  return True

def opt(robots):

  count = 0
  i = 1
  robot1 = robots[0]
  while i < len(robots):
    robot2 = robots[i]
    if robot1[1] > robot2[0]:
      if robot1[1] < robot2[1]:
        robot2 = robot1
        count += 1
      else:
        count += 1
    robot1 = robot2
    i += 1
  return count

print(opt(robots))

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: (x[0]+x[1],x[0]-x[1]))
M = XL[0][0]+XL[0][1]-1
ans = N
for i in range(1,N):
    if M >= XL[i][0]-XL[i][1]+1:
        ans -= 1
    else:
        M = XL[i][0]+XL[i][1]-1
print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
lst = []
for i in range(T):
    lst.append(list(map(int, input().split())))
lst.sort()
keep = 0
last_valid = 0
for z in range(1,T):
    if (lst[z][1] + lst[last_valid][1]) <= ( lst[z][0] - lst[last_valid][0] ):
        keep += 1
        last_valid = z
print(keep+1)

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数

N = iin()
XL = sorted([iln() for _ in range(N)], key=lambda x:x[0])

cnt = 0
prev_R = XL[0][0]+XL[0][1]
for i in range(1, N):
    if prev_R > (XL[i][0]-XL[i][1]):
        cnt += 1
    elif i+1 < N and (XL[i][0]+XL[i][1]) > (XL[i+1][0]-XL[i+1][1]):
        cnt += 1
    else:
        prev_R = XL[i-1][0]+XL[i-1][1]
print(N-cnt)

Submission status: Wrong Answer

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

segs = sorted([(p - r + 1, p + r - 1) for p, r in a], key=lambda x: x[1])
dp = [1]  + [0] * (n - 1)
for i in range(1, n):
    dp[i] = dp[i - 1]
    left, right = -1, i
    while left + 1 < right:
        mid = (left + right) >> 1
        if segs[mid][1] < segs[i][0]:
            left = mid
        else:
            right = mid
    if left != -1:
        dp[i] = max(dp[i], 1 + dp[left])
print(dp[n - 1])

Submission status: Wrong Answer

Solution code:
N=int(input())
xl=[list(map(int,input().split())) for _ in range(N)]
for i in range(N):
  x,l=xl[i]
  xl[i]=[x-l+1,x+l-1]
xl.sort()
a=0
r=xl[0][1]
for i in range(N-1):
  if r>xl[i+1][0]:
    a+=1
  else:
    r=xl[i+1][1]
    
xls=[[xl[i][1],xl[i][0]] for i in range(N)]
xls.sort(reverse=True)
b=0
l=xls[0][1]
for i in range(N-1):
  if l<xls[i+1][0]:
    b+=1
  else:
    l=xls[i+1][1]
    
print(N-min(a,b))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]", L: "List[int]"):
    xl = [[X[i], L[i]] for i in range(N)]
    xl = sorted(xl, key=lambda x:x[0])
    for i in range(1, N):
        t = i-1
        if xl[t][0] == -1:
            while(xl[t][0] != -1 and t > 0):
                t -= 1

        if xl[t][0]+xl[t][1] > xl[i][0]-xl[i][1]:
            xl[i][0] = -1


    y = [xl[i][0] for i in range(len(xl)) if xl[i][0] != -1]
    # print(y)
    print(len(y))

    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
    X = [int()] * (N)  # type: "List[int]"
    L = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        X[i] = int(next(tokens))
        L[i] = int(next(tokens))
    solve(N, X, L)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

class Robot:
    x = 0
    l = 0
    def __init__(self, x, l):
        self.x = x
        self.l = l

    # def __repr__(self):
    #     return f"x:{self.x} l:{self.l}"

N = int(input())
R = []
for n in range(N):
    x, l = list(map(int, input().split()))
    R += [Robot(x, l)]

R.sort(key=lambda r:r.x)

result = 0
last_robot = R[0]
for n in range(len(R) - 1):
    if R[n].x + R[n].l <= R[n + 1].x:
        last_robot = R[n + 1]
        result += 1
    else:
        last_robot = R[n]

# print(f"last_robot:{last_robot}")

if last_robot == R[-1] or last_robot == R[0]:
    result += 1

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = []
for _ in range(N):
    x, n = [int(i) for i in input().split()]
    p.append((x-n, x+n))
p.sort()
i = 0
j = 1
c=0
while i<N and j<N:
    # print(i, j)
    if p[i][0]<=p[j][0]<p[i][1]:
        j+=1
        c+=1
    else:
        i=j
        j+=1
print(N-c)

Submission status: Wrong Answer

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

import sys
from itertools import accumulate

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 list4d(a, b, c, d, e): return [[[[e] * d for j in range(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(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
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

def compress(S):
    """ 座標圧縮 """

    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(S)):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

N = INT()
LX = []
S = set()
for i in range(N):
    x, l = MAP()
    LX.append((l, x))
    S.add(x)
    S.add(x-l)
    S.add(x+l)
LX.sort()

zipped, _ = compress(S)
M = len(zipped)
LR = []
for i in range(N):
    l, x = LX[i]
    LR.append((zipped[x-l], zipped[x+l]))

imos = [0] * (M+1)
for i in range(N):
    l, r = LR[i]
    imos[l+1] += 1
    imos[r] -= 1
imos = list(accumulate(imos))

ans = N - (max(imos) - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np


def main():
	n=int(input())
	li=[]
	for i in range(n):
		x,l=map(int,input().split())
		li.append([x-l,x+l])
	li.sort(key=lambda x: x[0])
	
	b=li[0][1]
	ans=n
	
	for i in range(1,n):
		if li[i][0]<b:
			b=min(b,li[i][1])
			ans-=1
	print(ans)




if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
hani = []
for i in range(N):
    x, l = map(int, input().split())
    hani.append((x-l+1, x+l-1))
hani.sort(key = lambda x:x[1])
now = -10**20
ans = 0
for i in range(N):
    l, r = hani[i]
    if now<l:
        now = r
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = []
for i in range(n):
  x,l = map(int,input().split())
  a.append(x-1)
  b.append(x+l)
  for j in range(len(a)):
    if a[j]<x-l<b[j] or a[j]<x+l<b[j]:
      a.pop()
      b.pop()
      break
print(len(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
xl=[]
l=[]
for i in range(n):
    a,b=map(int,input().split())
    xl.append((a,b))
    l.append((a-b,i,0))
    l.append((a+b-0.1,i,1))
xl.sort()
l.sort()
buf=0
count=0
for i in range(2*n):
    if l[i][2]==0:
        buf+=1
    elif l[i][2]==1 and buf==1:
        buf=0
    elif buf>1:
        count+=buf-1
        buf=0
    #print(l[i],buf,count)
print(n-count)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	x = [list(map(int,input().split())) for _ in range(n)]
	x.sort(key = lambda x: x[0])
	i = 1
	ans = 0
	while i < n:
		if(sum(x[i-1]) > x[i][0] - x[i][1]):
			i += 1
			ans += 1
		i += 1

	if(n == 1):
		print(ans)
		return

	i = n - 2
	ans_ = 0
	while i > -1:
		if(sum(x[i]) > x[i+1][0] - x[i+1][1]):
			i -= 1
			ans_ += 1
		i -= 1
	print(n - min(ans,ans_))

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

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

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

tmp = sum(xl[0])

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

print(n-res)

Submission status: Wrong Answer

Solution code:
# 2020/01/18
# キーエンス プログラミング コンテスト 2020 - B

from operator import itemgetter

# Input
n = int(input())

in_list = list()

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

in_list.sort(key=itemgetter(0))

# Calc
wkx = in_list[0][0]
wkl = in_list[0][1]
ans = 1

for i in range(1, n):
    x = in_list[i][0]
    l = in_list[i][1]
    if wkx + wkl + l <= x:
        wkx = x
        wkl = l
        ans = ans + 1
    
# Output
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for i in range(N):
    XL.append(list(map(int,input().split())))
XL.sort(key=lambda x:x[0])
ans = 0
left = XL[0][0]-XL[0][1]
right = XL[0][0]+XL[0][1]
for i in range(1,N):
    new_left = XL[i][0]-XL[i][1]
    new_right = XL[i][0]+XL[i][1]
    #if no overlap
    if new_left >= right:
        left = new_left
        right = new_right
    else:
        ans += 1
        if (new_right-new_left) >= (right-left):
            left = new_left
            right = new_right
print(N-ans)

Submission status: Wrong Answer

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

robos.sort(key= lambda x:x[1])
# print(robos)
edge = -10000000000
out = 0
for i in range(n):
    if robos[i][0] > edge:
        out += 1
        edge = robos[i][1]
    else:
        continue

print(out)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    l.append(tuple(map(int,input().split())))
l = sorted(l)
ans = n
for i in range(n-1):
    L = l[i][0]+l[i][1]
    R = l[i+1][0]-l[i+1][1]
    if L > R:
        ans -= 1
        l[i+1] = l[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx,ll))
xl.sort()
x = [z[0] for z in xl]
l = [z[1] for z in xl]

ok = [1]*n
for i in range(1,n-1):
    if ok[i-1]==1 and x[i-1]+l[i-1] > x[i]-l[i] and \
       x[i]-l[i] > x[i+1]+l[i+1]:
        ok[i] = 0

for i in range(1,n):
    if x[i-1]+l[i-1] > x[i]-l[i] and ok[i-1]==1 and ok[i]==1:
        ok[i] = 0

print(sum(ok))

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for _ in range(N):
    x, l = map(int, input().split())
    XL.append([x, l])
XL.sort()
ans = 1
prev = XL[0]
for i in range(1, N):
    x, l = XL[i]
    if x - prev[0] - 1  - (l + prev[1] -1 )>= 0:
        ans += 1
        prev = [x, l]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
l = []
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    x.append(x1)
    l.append(l1)
    xl.append([x1, l1])
xl.sort()
for i in range(n):
    x[i] = xl[i][0]
    l[i] = xl[i][1]


now = 1
while now < len(x):
    if x[now - 1] + l[now - 1] > x[now] - l[now]:
        if now == len(x) - 1:
            del x[now]
            del l[now]
            break
        if x[now - 1] + l[now - 1] > x[now + 1] - l[now + 1]:
            del x[now - 1]
            del l[now - 1]
            now -= 1
        else:
            del x[now]
            del l[now]
            now -= 1
    now += 1
print(len(x))

Submission status: Wrong Answer

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

count = N
temp = X[0][0] + X[0][1]
for i in range(N - 1):
    if X[i + 1][0] - X[i + 1][1] < temp:
        count -= 1
    else:
        temp = X[i + 1][0] + X[i + 1][1]

print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d = defaultdict(list)
for i in [0]*N:
    X,L = map(int, input().split(' '))
    d[X-L].append(X+L)
ps = sorted(list(d.items()))
ans = 0
now = -10**10
for p, e in ps:
    if now <= p:
        now = min(e)
        ans += 1
print(ans)