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())
arr=[]
for i in range(n):
	x,l=map(int,input().split())
	arr.append([x-l+1,x+l-1])
arr=sorted(arr,key=lambda item:item[1])
cc=1
r1=arr[0][1]
for i in range(1,len(arr)):
	l1=arr[i][0]
	r2=arr[i][1]
	if l1>r1:
		cc+=1
		r1=r2
print(cc)

Submission status: Wrong Answer

Solution code:
n = int(input())
rx = {}

minrx = 10 ** 10
minrx_idx = -1
for i in range(n):
    xx, ll = map(int, input().split(' '))
    rx[xx - ll] = (xx - ll, xx + ll)

rxs = sorted(rx.items(), key=lambda x:x[0])

rxs2 = [i[1] for i in rxs]

now_idx = 0
cnt = 1
for i, x in enumerate(rxs2):
    if now_idx == i:
        continue
    if rxs2[now_idx][1] > rxs2[i][0]:
        continue
    now_idx += 1
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
c=0
d=[]
e=[]
for i in range(n):
    b=list(map(int,input().split()))
    a.append([b[0]-b[1],1])
    a.append([b[0]+b[1],-1])
a=sorted(a,key=lambda x:(x[0],x[1]))
for i in range(n*2):
    c+=a[i][1]
    if c==0:
        e.append(d)
        d=[]
    d.append(max(c-1,0))
for i in range(len(e)):
    n-=max(e[i])
print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
robot = {}

for i in range(N):
  x, l = map(int, input().split())
  robot[x] = l

s_robot = sorted(robot.items(), key=lambda x:x[0])

pre_arm = -10**20
cnt = 0
for key, val in s_robot:
  l_arm = key - val
  r_arm = key + val
  if pre_arm > l_arm:
    cnt += 1
  else:
    pre_arm = r_arm
    
print(N-cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
ans2=1
cnt=-(10**9)
cnt2=-(10**9)
li=[]
for i in range(n):
    X,L=map(int,input().split())
    li.append([X,L])
li=sorted(li,key=lambda x:x[0])
for i in range(n):
    if cnt>li[i][0]-li[i][1]:
        ans+=1
    else:
        cnt=li[i][0]+li[i][1]
for i in range(1,n):
    if cnt2>li[i][0]-li[i][1]:
        ans2+=1
    else:
        cnt2=li[i][0]+li[i][1]
print(n-min(ans,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())
r = []
for _ in range(n):
    r.append(list(map(int,input().split())))
r.sort()
i = 0
j = 1
cnt = 0
while i <= n-2 and i+j < n:
    if r[i][0] + r[i][1] > r[i+j][0] - r[i+j][1]:
        j += 1
        cnt += 1
    else:
        i += j
        j = 1
print(n-cnt)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    xl = []
    m = []
    cnt = 0
    num = 0
    n = int(input())
    for i in range(n):
        tmp = input().split(" ")
        xl.append([int(tmp[0]), int(tmp[1])])
    xl.sort()
    for i in range(n):
        m.append([xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]])
    while num < n - 1:
        flg = False
        if m[num][1] > m[num + 1][0]:
            cnt += 1
            num += 1
            for j in range(n-num):
                if m[num][1] < m[num + j][0]:
                    num += j-1
                    cnt += j
                    flg = True
                    break
            if not flg:
                cnt += n-num-1

        num += 1
    print(n-cnt)


if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
robots = {}
for _ in range(N):
    pos,armlen = map(int,input().split())
    robots[pos] = armlen

robots = sorted(robots.items(),key=lambda x:x[0])
range_min = robots[0][0] + robots[0][1]
ans = 1
for robot in robots[1:]:
    pos,armlen = robot
    if pos >= range_min and  range_min <= (pos-armlen):
        ans += 1
        range_min = pos+armlen

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
x = [xl_i[0] for xl_i in xl]
x_idx = sorted(range(len(x)), key=lambda k: x[k])
xl = [xl[i] for i in x_idx]

j = 1
while j < len(xl):
    x_i, l_i = xl[j-1]
    x_j, l_j = xl[j]
    if (x_i + l_i) > (x_j - l_j):
        xl.remove(xl[j])
        j = 0
    j += 1

print(len(xl))

Submission status: Wrong Answer

Solution code:
n = int(input())
xl_array = sorted([[int(x) for x in input().split()] for y in range(n)])
cnt = 0
tmp = -float("inf")
for x, l in xl_array:
    if x - l >= tmp:
        cnt += 1
        tmp = x + l
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = list(list(map(int,input().split())) for _ in range(N))
X.sort()
# print(X)
ans = N
for i in range(N-1):
    # print(X[i][0] + X[i][1],X[i+1][0] - X[i+1][1])
    if X[i][0] + X[i][1] <= X[i+1][0] - X[i+1][1]:
        pass
    else:
        ans -= 1
X.sort(reverse=True)
ans2 = 0
for i in range(N-1):
    # print(X[i][0] + X[i][1],X[i+1][0] - X[i+1][1])
    if X[i][0] + X[i][1] <= X[i+1][0] - X[i+1][1]:
        pass
    else:
        ans2 -= 1
print(max(abs(ans), abs(ans2)))
# print(X)

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)
  else:
    arm_long_new = i[0] + i[1] - 1
    if arm_long > arm_long_new:
      ans_list[-1] = i

print(len(ans_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()
cur_max = 0
cnt = 0

for i in range(n):
  xl = XL[i]
  tmp = xl[0]+xl[1]
  if xl[0]>= cur_max:
    cur_max = tmp
    cnt += 1
    
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    xls_input = [[int(k) for k in input().split(" ")] for n in range(N)]
    xls_input.sort()

    xls = []

    ans = N
    for i in range(N):
        xl = xls_input[i]
        if i == 0:
            xls.append(xl)
        else:
            xl_before = xls[-1]
            x_before = xl_before[0]
            l_before = xl_before[1]
            x = xl[0]
            l = xl[1]
            if abs(x - x_before) < l + l_before:
                ans -= 1
            else:
                xls.append(xl)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

min = []
max = []
for i in range(n):
    min1, max1 = (x[i]-l[i],x[i]+l[i])
    min.append(min1)
    max.append(max1)

min_sort = sorted(min)
max_sort = sorted(max)
ans = 0
T =max_sort[0]
for i in range(n-1):
    if T<=min_sort[i+1]:
        ans +=1
        T = max_sort[i+1]
print(ans+1)

Submission status: Wrong Answer

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

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

ans = 1
t = XL[0][1]
for i in range(1,N):
    if t <= XL[i][0]:
        ans += 1
        t = XL[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
segs = [[0,0]]*N

X = [0]*N
L = [0]*N
for i in range(N):
    X[i],L[i] = map(int,input().split())

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

ans=0
seg = segs.pop()
#while len(segs)!=0:
    
while len(segs)!=0:
    seg2 = segs.pop()
    if len(segs)==0:
        ans += 1
    if seg[1]>seg2[0]:
        if seg[1]<=seg2[1]:
            continue
        else:
            seg=seg2
    else:
        ans+=1
        seg=seg2
        

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=[]
for i in range(n):
	x,y=map(int,input().split())
	arr.append([x,y])
arr=sorted(arr,key=lambda item:item[1])
cc=1
r1=arr[0][1]
for i in range(1,len(arr)):
	l1=arr[i][0]
	r2=arr[i][1]
	if l1>r1:
		cc+=1
		r1=r2
print(cc)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [0]*n
l = [0]*n
li = []
for i in range(n):
  x[i], l[i] = list(map(int, input().split()))
  li.append([x[i], l[i]])
li.sort()
 
count = 0
if n == 2:
  if (li[0][0] + li[0][1]) >= (li[1][0] - li[1][1]):
    print(1)
  else:
    print(n)
else:
  for i in range(n):
    if i == n-1:
      continue
    else:
      top = (li[i][0] + li[i][1]) >= (li[i+1][0] - li[i+1][1])  
      if top == False:
        count += 1

  print(n - count)

Submission status: Wrong Answer

Solution code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi, li))
robots.sort()
cnt = [0] * n
for i in range(1, n):
    nl = robots[i][0] - robots[i][1]
    nr = robots[i][0] + robots[i][1]
    ol = robots[i - 1][0] - robots[i - 1][1]
    oright = robots[i - 1][0] + robots[i - 1][1]
    if oright > nl:
        cnt[i] += 1
        cnt[i - 1] += 1
ans = n
for i in range(n):
    if cnt[i] > 1:
        cnt[i - 1] -= 1
        cnt[i] = 0
        cnt[i + 1] -= 1
        ans -= 1
ans -= cnt.count(1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

r = [[0,0] for i in range(n)]

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

ans = 0

r = dict(r) #辞書型にする
r = sorted(r.items())

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

print(n-ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
lr = sorted([[xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]] for i in range(n)], key=lambda x:[x[0],-x[1]])

cnt = 1
cl = lr[0][0]
cr = lr[0][1]
for l,r in lr[1:]:
    if cr<=l:
        cr = r
        cl = l
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
rs = [list(map(int, input().split())) for _ in range(n)]
rs = np.array(rs)
rs.sort(axis=0)

cnt = 0
reach = None
for i in range(n):
    x, l = rs[i]
    if i != 0 and x - l < reach:
        continue
    reach = x + l
    cnt += 1
print(cnt)

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:
from operator import itemgetter
n = int(input())
ans = n
A = []
for i in range(n):
    x, l = [int(i) for i in input().split()]
    A.append([x-l, x+l])
A = sorted(A, key = itemgetter(0))
cur_end = A[0][1]
for i in range(n-1):
    if cur_end > A[i+1][0]:
        ans -= 1
    cur_end = min(A[i+1][1], cur_end)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

XL = []
for i in range(N):
    tmp = list(map(int, input().split()))
    XL.append(tmp)
    
XL = sorted(XL, key=lambda x:x[0])

i = 0
now = 0
count = 0
while i <= len(XL)-2:
    now_arm = XL[now][0] + XL[now][1]
    if now_arm > XL[i+1][0] - XL[i+1][1]:
        count += 1
        if XL[i+1][0] + XL[i+1][0] < now_arm:
            now = i
        else:
            pass
    else:
        now = i
    i += 1    


#print(XL)
print(len(XL) - count)

Submission status: Wrong Answer

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

xl.sort()
lr.sort()
lr.append([-float("inf"), -float("inf")])

l = lr[0][0]
r = lr[0][1]

ans = 0
for i in range(1, len(lr)):
    if  lr[i][0] <= r:
        l = lr[i][0]
        r = lr[i][1]
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
robot = {}

for i in range(N):
  x, l = map(int, input().split())
  robot[x] = l

s_robot = sorted(robot.items(), key=lambda x:x[0])

pre_arm = -10**10
cnt = 0
for key, val in s_robot:
  l_arm = key - val
  r_arm = key + val
  if pre_arm > l_arm:
    cnt += 1
  else:
    pre_arm = r_arm
    
print(N-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

r = []
for i in range(N):
  r.append(list(map(int, input().split())))
r.sort(key=lambda x: x[0])

left = [[r[0][0], r[0][1]]]
for i in range(1, N):
  if left[-1][0]+left[-1][1] <= r[i][0]-r[i][1]:
    left.append([r[i][0], r[i][1]])

right = [[r[N-1][0], r[N-1][1]]]
for i in range(N-2, -1, -1):
  if right[-1][0]-right[-1][1] >= r[i][0]+r[i][1]:
    right.append([r[i][0], r[i][1]])

print(max(len(left), len(right)))

Submission status: Wrong Answer

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l+1, x+l-1))
Y.sort(key=lambda x: x[0])

cnt = 0
l0, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r >= l0:
        cnt += 1
        if r0 > r:
            l0, r0 = l, r
print(n-cnt)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xl = [LI() for _ in range(n)]
lst = []
for x,l in xl:
    lst.append((x-l,x+l))
lst.sort(key = itemgetter(0))
ans = 0
i = 0
while i < n:
    (l,r) = lst[i]
    j = i+1
    while j < n:
        (l1,r1) = lst[j]
        if l < l1 < r:
            ans += 1
        else:
            break
        j += 1
    i = j
print(n-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    XL.append(array)
XL = sorted(XL)
Y = 0
cnt = 0
for i in range(N):
    if XL[i][0]-XL[i][1]>=Y:
        cnt += 1
        Y = XL[i][0]+XL[i][1]
    else:
        Y = min(Y,XL[i][0]+XL[i][1])
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = [None]*N
for i in range(N):
    l[i] = list(map(int, input().split()))
l.sort()
prek = l[0][0]
prea = l[0][1]
cnt = N

for i in range(1,N):
    k,a = l[i]
    pre_reach = prek+a-1
    now_reach_m = k-a+1
    now_reach_p = k+a-1
    if pre_reach>=now_reach_m:
        #前の範囲が今回の範囲よりplusに長ければ前のアームを消す
        if pre_reach>now_reach_p:
            cnt -= 1
            prek = k
            prea = a
        else:
            cnt -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def int_input():
    return int(input())

def multi_int_input():
    return map(int, input().split())

robot_num = int_input()

robot_stock = []

for i in range(robot_num):
    robot_coor, robot_len = multi_int_input()
    if robot_stock:
        robot_stock.append((max(0, robot_coor - robot_len),
                                robot_coor + robot_len))
    else:
        robot_stock.append((max(0, robot_coor - robot_len),
                                robot_coor + robot_len))

robot_stock = sorted(robot_stock, key=lambda x: x[0])

remove_stock = []
for i, rs in enumerate(robot_stock):
        other_stock = robot_stock[i+1:]
        for os in other_stock:
            if os[0] < rs[1]:
                remove_stock.append(i)
                
print(len(robot_stock) - len(remove_stock))

Submission status: Wrong Answer

Solution code:
n = int(input())
xl_lis = [list(map(int,input().split())) for i in range(n)]
tempx = -(10**10)
ans = 0
xl_lis.sort()
# print(xl_lis)
for i in range(n):
    if tempx > xl_lis[i][0] - xl_lis[i][1] and tempx < xl_lis[i][0] + xl_lis[i][1]:
        ans += 1
    
    elif tempx > xl_lis[i][0] - xl_lis[i][1] and tempx > xl_lis[i][0] + xl_lis[i][1]:
        ans += 1
        tempx = xl_lis[i][0] + xl_lis[i][1]
    elif tempx < xl_lis[i][0] + xl_lis[i][1]:
        tempx = xl_lis[i][0] + xl_lis[i][1]
print(n-ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n = int(input())
xl = sorted([[int(i) for i in input().split()] for i in range(n)],key=itemgetter(0))

hani = []
for t in xl:
    x,l = t
    hani += [x-l,x+l]

ans = n * 2
for i in range(1,n*2):
    if hani[i-1] > hani[i]: ans -= 1
print(ans // 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [list(map(int,input().split())) for _ in range(N)]
XL.sort()
r_l = []
number = [0]*N
S = 0
for n in range(N):
  xl = XL[n]
  x = xl[0]
  l = xl[1]
  r_l.append([x-l,x+l])
  
i = 1
while True:
  if i>N-1:
    break
  if r_l[0][1]>r_l[i][0]:
    number[0] += 1
    S += 1
    i += 1
  else:
    break
    
i = N-2
while True:
  if i<0:
    break
  if r_l[N-1][0]<r_l[i][1]:
    number[N-1] += 1
    S+=1
    i -= 1
  else:
    break
    
for i in range(1,N-1):
  j = i-1
  while True:
    if j<0:
      break
    if r_l[i][0]<r_l[j][1]:
      number[i] += 1
      j-= 1
      S+=1
    else:
      break
      
  j = i+1
  while True:
    if j>N-1:
      break
    if r_l[i][1]>r_l[j][0]:
      number[i] += 1
      j += 1
      S+=1
    else:
      break

ans = N
S //= 2
number.sort(reverse = True)
for i in number:
  if S==0:
    break
  S -= i
  ans -= 1
    
print(ans)

Submission status: Wrong Answer

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

i = 0
while i != len(robot) - 1:
    if robot[i][0] + robot[i][1] > robot[i+1][0] - robot[i+1][1]:
        robot.pop(i+1)

    else:
        i += 1

print(len(robot))

Submission status: Wrong Answer

Solution code:
N = int(input())
XLlist = [tuple(map(int, input().split())) for _ in range(N)]
XLlist.sort(key=lambda x: x[0])
ans = 1
x, l = XLlist[0]
rl = x + (l - 1)

for x, l in XLlist[1:]:
    l -= 1
    ll = x - l
    if ll <= rl:
        rl = min(rl, x + l)
    else:
        ans += 1
        rl = x + l
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

L=[]
for i in range(n):
    x,l=map(int,input().split())
    L.append([x,l])
L.sort(key=lambda x:x[0])

ans=1
before=L[0][0]+L[0][1]
for i in range(1,n):
    if before<=L[i][0]-L[i][1]:
        before=L[i][0]+L[i][1]
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,*t=map(int,open(0).read().split())
*z,=sorted(zip(*[iter(t)]*2))
s=set()
for i in range(n-1):
    if i in s:
        continue
    x,l=z[i]
    j=i+1
    while 1:
        y,r=z[j]
        if x+l>y-r:
            if y+r<x+l:
                s|={i}
            else:
                s|={j}
        else:
            break
        j+=1
        if j==n:break
print(n-len(s))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

for i in range(N):
    if robots[i][-1]:
        continue
    if i != N-1:
        if robots[i][0] + robots[i][1] - 1 >= robots[i+1][0] - robots[i+1][1] + 1:
            robots[i+1][-1] = True

ans = 0
for robot in robots:
    if not robot[-1]:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

lob = []

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

lob.sort()

ans = 0
last = 0
for l in lob:
    if last <= l[1]:
        ans += 1
        last = l[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
xl = [na() for i in range(n)]
xl.sort()

res = 0
for i in range(1, n):
    if xl[i - 1][0] + xl[i - 1][1] - 1 >= xl[i][0] - xl[i][1] + 1:
        res += 1
        xl[i][0] = -(1 << 60)
        xl[i][1] = 0

print(n - res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    x = [[0, 0] for  _ in range(n)]
    for i in range(n):
        x[i] = list(map(int, input().strip().split()))
    x = sorted(x, key=itemgetter(1))
    m = x[0][1]
    ans = 1
    for mi, ma in x[1:]:
        if m <= mi:
            m = ma
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
p=[[-1,-1] for i in range(n)]
p[0]=[0,1]
x,l=[],[]
y=[]
for i in range(n):
    y.append(list(map(int,input().split())))
y.sort()
x=[y[i][0] for i in range(n)]
l=[y[i][1] for i in range(n)]

a=[x[i]+l[i] for i in range(n)]
for i in range(1,n):
    s=bisect.bisect_right(a,x[i]-l[i])
    if s>0:
        p[i]=[max(p[i-1]),max(p[s-1])+1]
    else:
        p[i]=[max(p[i-1]),1]
print(max(p[n-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
robots = []
for _ in range(N):
    X , L = map(int,input().split())
    robots.append([X - L, X + L])
robots.sort()
now = robots[0][1]
remove_num = 0
for i in range(1, N):
    if robots[i][0] >= now:
        now = robots[i][1]
    else:
        remove_num += 1
print(N - remove_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = []
ans = n
for i in range(n):
    x, l = map(int, input().split())
    xl.append([x, l])
x1 = 0
x2 = 1
xl.sort()
while x2 < n:
    f = xl[x1][0] + xl[x1][1] - 1
    s = xl[x2][0] - xl[x2][1] + 1
    if s < f:
        x2 += 1
        ans -= 1
    else:
        x1 += 1
        x2 += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

N=int(input())


l=[]

for i in range(N):
	a,b=map(int,input().split())
	st,fin=(a-b,a+b)
	l.append([fin,st])


list=sorted(l)

pt=list[0][1]
cnt=1


for j in range(1,N):
	if pt<= list[j][1]:
		cnt+=1
		pt=list[j][0]

print(cnt)

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 bisect

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


XL = sorted(XL)
MM.sort(key=lambda x: x[0])
MM.sort(key=lambda x: x[1])
migi = []
for i in range(N):
    migi.append(MM[i][1])
    
dp = [0]*(N+1)
dp[0] = 1
#print(MM)
for i in range(1,N):
    k = bisect.bisect_right(migi,MM[i][0]) - 1
    #print(k)
    if k >= 0:
        dp[i] = dp[k] + 1
    else:
        dp[i] = 1

ans = max(dp)
#print(dp)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
AB=[]
for i in range(n):
    x,l=map(int,input().split())
    a=x-l
    b=x+l
    AB.append((a,b))
cnt=1
AB.sort(key=lambda L:L[1], reverse=True)
simekiri=AB[0][0]
for i in range(1,n):
    migi=AB[i][1]
    hidari=AB[i][0]
    if migi<=simekiri:
        cnt+=1
        simekiri=hidari
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ES = []
for i in range(N):
    x,l = list(map(int,input().split()))
    ES.append((min(x+l-1,10**9),max(x-l+1,0)))

ES = sorted(ES)
# print(ES)

sel = []
cur = None
for E,S in ES:
    if cur is None or cur < S:
        sel.append((E,S))
        cur = E
# print(sel)
print(len(sel))

Submission status: Wrong Answer

Solution code:
import math
def main():
    N = int(input())
    robo = []
    min = 0
    for _ in range(N):
        x, l = map(int, input().split())
        l = l-1
        if (x-l) < min:
            min = x - l
        robo.append((x+l, x-l))

    robo = sorted(robo, key=lambda x: x[0])

    ans = 0
    t = -100000000000000000000000000000000000000000000000000000000
    for i in range(N):
        if t < robo[i][1]+min:
            ans += 1
            t = robo[i][0]+min

    print(ans)




    return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
a = []
p = []
res = 0
for _ in range(N):
  x, l = map(int, input().split())
  a.append((x, l))
  p.append(x)
p.sort()
for i in range(N):
  l = bl(p, a[i][0] - a[i][1] + 1)
  r = bl(p, a[i][0] + a[i][1] - 1)
  res += max(r - l - 1, 0)
print(N - res // 2)

Submission status: Wrong Answer

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

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

# print(rb)
rmSet = set()

# rb.sort(key=lambda x:x[0])
rb.sort()
r = rb[0][0] + rb[0][1]

# print(rb)

for i in range(1, n):
    # print(i, r)
    l1 = rb[i][0] - rb[i][1]

    # Skip if not overlapped with previous one
    if l1 >= r:
        r = rb[i][0] + rb[i][1]
        continue

    r1 = rb[i][0] + rb[i][1]

    # Remove self if r is bigger than previous one
    if r1 > r:
        # print('(A) remove!')
        rmSet.add(rb[i][0])
    else:
        # print('(B) remove!')
        r = r1
        rmSet.add(rb[i-1][0])

# print(rmSet)

print(n - len(rmSet))

Submission status: Wrong Answer

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

robot_num = n

for i in range(len(xl)):
    try:
        if (sum(xl[i]) > xl[i + 1][0]):
            robot_num -= 1
    except:
        break

print(robot_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [tuple(map(int,input().split())) for _ in range(n)]
xl.sort(key = lambda x:x[0]+x[1],reverse = True)
mini = xl[0][0]+xl[0][1]
ans = n
for i in range(n):
  if mini < xl[i][0]+xl[i][1]:
    ans -= 1
  else:
    mini = min(xl[i][0]-xl[i][1],mini)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    XL.append(array)
XL = sorted(XL)
Y = 0
cnt = 0
for i in range(N):
    if XL[i][0]>=Y:
        cnt += 1
        Y = XL[i][0]+XL[i][1]
    else:
        Y = min(Y,XL[i][0]+XL[i][1])
print(cnt)

Submission status: Wrong Answer

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

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

min = []
max = []
for i in range(n):
    min1, max1 = (x[i]-l[i],x[i]+l[i])
    min.append(min1)
    max.append(max1)

min_sort = sorted(min)
max_sort = sorted(max)
ans = 0
T =-100000000
for i in range(n):
    if T<=min_sort[i]:
        ans +=1
        T = max_sort[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
XL=[]
L=10**10
R=-10**10
for i in range(N):
  s=input().split(" ")
  XL+=[[int(s[0]),int(s[1])]]
  L=min(L,XL[-1][0]-XL[-1][1])
  R=max(R,XL[-1][0]+XL[-1][1])
XL.sort()
for i in range(N):
  XL[i]=[0,XL[i][0],XL[i][1]]

for i in range(N-1):
  for j in range(i+1,N):
    if XL[i][1]+XL[i][2]>XL[j][1]-XL[j][2]:
      XL[i][0]+=1
      XL[j][0]+=1
    else:
      break

while True:
  #print(XL)
  max_id=0
  max_val=0
  for i in range(N):
    if XL[max_id][0]<XL[i][0]:
      max_id=i
      max_val=XL[i][0]
  if max_val==0:
    print(N)
    break
  i=max_id+1
  while i<N:
    if XL[max_id][1]+XL[max_id][2]>XL[i][1]-XL[i][2]:
      XL[i][0]-=1
      i+=1
    else:
      break
  i=max_id-1
  while i>=0:
    if XL[max_id][1]-XL[max_id][2]<XL[i][1]+XL[i][2]:
      XL[i][0]-=1
      i-=1
    else:
      break
  XL.pop(max_id)
  N-=1

Submission status: Wrong Answer

Solution code:
s = input()
k = []
for i in range(s):
        q = list(map(int,raw_input().split()))
        k.append(q)

k.sort()

p = 0
count =0
for i in range(s-1):
        k1 = k[i][0]+k[i][1]
        k2 = k[i+1][0]-k[i][1]
        if k1 > k2 :
                count += 1
                if p == k[i][0]:
                        count -= 1
        p = k[i+1][0]

print(s - count)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    sys.setrecursionlimit(10**7)
    input = sys.stdin.readline

    N = int(input())
    XL = []
    for i in range(N):
        X, L = map(int, input().split())
        XL.append((X+L, X-L, X, L))
    memo = [None] * (N+1)
    memo[0] = 0
    memo[1] = 1
    XL = sorted(XL)
    #print(XL)
    print(solve(N, XL, memo))
    #print(memo)

def solve(N, XL, memo):
    if N < 2:
        if N == 0:
            return 0
        if N == 1:
            return 1
    if memo[N] is not None:
        return memo[N]


    R1, L1, X1, A1 = XL[N-2]
    R2, L2, X2, A2 = XL[N-1]

    # a1 X2 を残す
    a1 = 1
    for i in range(N-1)[::-1]:
        r, l, x, a = XL[i]
        if r <= L2:
            a1 = solve(i+1, XL, memo)+1
            memo[i+1] = a1
            break
    # a2
    a2 = solve(N-1, XL, memo)
    memo[N-1] = a
    a = max(a1, a2)
    memo[N] = a
    #print("solve(%d)=%d, a1=%d, a2=%d"% (N, a, a1, a2))
    return a

main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

for i in range(N):
    if robots[i][-1]:
        continue
    if i != N-1:
        if robots[i][0] + robots[i][1] - 1 >= robots[i+1][0] - robots[i+1][1] + 1:
            robots[i+1][-1] = True
    else:
        shift = 0
        skip = False
        while 1:
            if i - 1 - shift < 0:
                skip = True
                break
            if robots[i-1-shift][-1]:
                shift += 1
            else:
                break
        if (not skip) and robots[i][0] - robots[i][1] + 1 <= robots[i-1][0] + robots[i-1][1] - 1:
            robots[i][-1] = True

ans = 0
for robot in robots:
    if not robot[-1]:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

    X_L = tuple(tuple(int(j) for j in input().split()) for i in range(N))
    ranges = tuple((x - l, x + l) for x, l in X_L)

    sorted_ranges = sorted(ranges, key=lambda x: x[0])


    x_max = - 1e9
    x_min = 2e9

    allowed = []

    for i in range(N):
        i_min = sorted_ranges[i][0]
        i_max = sorted_ranges[i][1]

        if i_min >= x_max or i_max <= i_min:
            allowed.append(sorted_ranges[i])
            x_max = max(x_max, i_max)
            x_min = min(x_min, i_min)

    print(len(allowed))


if __name__ == '__main__':
    main()