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:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    robo = []
    for i in range(N):
        x, l = [int(x) for x in input().split()]
        robo.append((x-l, x+l))
    robo.sort(key=lambda x: x[1])

    ans = N
    l, r = robo[0]
    for i in range(1, N):
        if robo[i][0] < r:
            ans -= 1
        else:
            l, r = robo[1]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = n
r = ll.pop(0)[1]

while ll:
  while ll and ll[0][0] < r:
    ans -= 1
    ll.pop(0)
  if ll:
    r = ll.pop(0)[1]

print(ans)

Submission status: Wrong Answer

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

ES = sorted(ES)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = [tuple(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -float('inf')
ans = 0
for x,l in XL:
    s,t = x-l+1, x+l-1
    if s > right:
        right = t
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[]
for i in range(n):
    x,l=map(int,input().split())
    w.append([x-l,x+l])
w=sorted(w)
val=-(10**10)
ans=0
for i in range(n):
    if val<=w[i][0]:
        ans+=1
        val=w[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
X=[]
ans=0
for i in range(N):
    H = list(map(int, input().split()))
    O=[]
    O.append(H[0]-H[1])
    O.append(H[0]+H[1])
    X.append(O)
#print(X)
X=sorted(X, key=itemgetter(1))
S=X[0][1]
ans+=1
for i in range(len(X)):
    if(X[i][0]>S):
        ans+=1
        S=X[i][1]
"""
while(len(X)>0):
    #print(X)
    ans+=1
    S=X[0][1]
    X.remove(X[0])
    I = []
    for i in range(len(X)):
        if(X[i][0]>=S):
            I.append(X[i])
    X=I
    #print(I)
"""


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] > limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = [list(map(int,input().split())) for i in range(n)]
arr.sort()
outcount = 0
#リストの数を減らすと最後の２つがぶつかってた場合が判定できない
#時間がかかりすぎ1回okだったところは次はパスしたい
outnum = 0
def saiki():
    global outcount
    global outnum
    for i in range(outnum, len(arr)-2):
        if arr[i][0] + arr[i][1] > arr[i+1][0] - arr[i+1][1]:#アウトの条件
            outcount += 1
            outnum = i
            if [i+1][0] + arr[i+1][1] <= arr[i+2][0] - arr[i+2][1]:#1つあとのやつがぶつかってるか
                arr.pop(i)
            else:
                arr.pop(i + 1)
            return 'no'


while saiki() == 'no':
    saiki()

print(n - outcount)

Submission status: Wrong Answer

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[1])
cnt = 0
tmp = -10 ** 18
print(rl)
for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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[1])
li.sort(key=lambda x:x[0])

ans = 0
t = 0 - 10**9 + 99
for i in range(N):
    if t <= li[i][0]:
        ans += 1
        t = li[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort(key=lambda x: x[0])
cnt = 0
tmp = -10 ** 18

for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[]
for i in range(n):
    x,l=map(int,input().split())
    w.append([x-l,x+l])
w=sorted(w)
max=w[0][1]
ans=0
for i in range(1,n):
    if w[i][0]<max:
        ans+=1
    else:
        max=w[i][1]
print(n-ans)

Submission status: Wrong Answer

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


def main():
    N = int(input())
    robo = []
    for i in range(N):
        x, l = [int(x) for x in input().split()]
        robo.append((x, l))
    robo.sort()

    ans = N
    x0, l0 = robo[0]
    for i in range(1, N):
        x, l = robo[i]
        if x - l < x0 + l0:
            ans -= 1
        else:
            x0, l0 = x, l

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
rl = []
for i in range(N):
    rl.append((xl[i][0] - xl[i][1], xl[i][0] + xl[i][1]))
rl.sort()
cnt = 0
tmp = -10 ** 18

for i, j in rl:
    if tmp <= i:
        cnt += 1
        tmp = j
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[]
for i in range(n):
    x,l=map(int,input().split())
    w.append([x-l,x+l])
w=sorted(w)
print(w)
max=w[0][1]
ans=0
for i in range(1,n):
    if w[i][0]<max:
        ans+=1
    else:
        max=w[i][1]
print(n-ans)

Submission status: Wrong Answer

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

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        ans -= 1
        p = min(p,d[i][1])
    else:
        p = d[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort(key=lambda _x: _x[1])
cnt = 0
limit = r[0][0] - 1
for ri in r:
    if ri[0] > limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Submission status: Wrong Answer

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

def saiki():
    global outcount
    for i in range(len(arr)-2):
        if arr[i][0] + arr[i][1] > arr[i+1][0] - arr[i+1][1]:#アウトの条件
            outcount += 1
            if [i+1][0] + arr[i+1][1] <= arr[i+2][0] - arr[i+2][1]:#1つあとのやつがぶつかってるか
                arr.pop(i)
            else:
                arr.pop(i + 1)
            return 'no'


while saiki() == 'no':
    saiki()

print(n - outcount)

Submission status: Wrong Answer

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

ans = 0
last = -1e10
for r, l in R:
    if last <= l:
        ans += 1
        last = r
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ranges = []
for _ in range(N):
    x, l = map(int, input().split())
    ranges.append([x + l - 1, x - l + 1])
ranges.sort()

sx = ranges[0][0]
ans = 1
for i in range(N):
    if sx <= ranges[i][1]:
        ans += 1
        sx = ranges[i][0]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [tuple(map(int, input().split())) for i in range(N)]
T = list(map(lambda j:(j[0]-j[1]+1, j[0]+j[1]-1), S))

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

for i, t in enumerate(T):
  if i>0:
    if end < t[0]:
      res += 1
      start = t[0]
      end = t[1]
  else:
    start = t[0]
    end = t[1]
    res = 1

print(res)

Submission status: Wrong Answer

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

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        ans -= 1
        p = min(p,d[i][1])
    else:
        p = d[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 1
a = []
for i in range(n):
  x,l = map(int, input().split())
  a.append((x+l,x-l))
if n == 1:
  print(ans)
else:
  a.sort(key=lambda x:(x[0],x[1]))
  gl = a[0][0]
  st = a[0][1]
  for i in range(1,n):
    if gl<=a[i][1]:
      ans += 1
      gl = a[i][0]
print(ans)

Submission status: Wrong Answer

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

ans = 0
last = -1e10
for r, l in R:
    if last < l:
        ans += 1
        last = r
print(ans)

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], reverse=True)
cnt = 1
tmp1 = xl[0][0] - xl[0][1]
for i in range(1, N):
    tmp2 = xl[i][0] + xl[i][1]
    if tmp2 <= tmp1:
        cnt += 1
        tmp1 = xl[i][0] - xl[i][1]

print(cnt)

Submission status: Wrong Answer

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

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

for i in range(n):
    grid[i][0] = x[i][0] - x[i][1]
    grid[i][1] = x[i][0] + x[i][1]

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

for i in range(n):
    for j in range(i+1,n):
        if j >= len(new_grid):
            break
        if new_grid[i][0] == new_grid[i+1][0]:
            del new_grid[i+1]
            break
        if new_grid[i][1] > new_grid[j][0]:
            del new_grid[i+1]
            break

print(len(new_grid))

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


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

    xlr.sort(key=itemgetter(1))

    ans = N
    mi = xlr[0][1]
    for i in range(N - 1):
        if xlr[i + 1][0] < mi:
            mi = min(xlr[i + 1][1], mi)
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

temp = l[0][1]
count = n
i = 1
while(i<n):
  if temp <= l[i][1]:
    i = i + 1
  else:
    temp = min(temp,l[i][1])
    count -= 1
    i = i + 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = []
left = []
right = []
for i in range(n):
    x,l = map(int, input().split())
    # num , left , right
    d.append([x-l,x+l])

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        ans -= 1
        p = min(p,d[i][1])
    else:
        p = d[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ranges = []
for _ in range(N):
    x, l = map(int, input().split())
    ranges.append([x - l + 1, x + l - 1])
ranges.sort(key=lambda x:x[1])

prv_idx = 0
idx = 1
removed_num = 0
while idx <= N-1:
    if ranges[idx][0] <= ranges[prv_idx][1]:
        removed_num += 1
        if ranges[prv_idx][1] < ranges[idx][1]:
            prv_idx = idx
        idx += 1
    else:
        idx += 1
        prv_idx += 1
    if N - 1 < idx:
        break
print(N - removed_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = []
left = []
right = []
for i in range(n):
    x,l = map(int, input().split())
    # num , left , right
    d.append([x-l,x+l])

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        ans -= 1
        p = d[i][1]
    else:
        p = min(p,d[i][1])
print(ans)

Submission status: Wrong Answer

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

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

j = 0
k = 0
for i in range(N):
  if k == 0 or k <= X_L_list[i][0] - X_L_list[i][1]:
    j = j + 1
    k = X_L_list[i][0] + X_L_list[i][1]

print(j)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 1
a = []
d = {}
for i in range(n):
  x,l = map(int, input().split())
  a.append((x+l,x-l))
if n == 1:
  print(ans)
else:
  a.sort()
  gl = a[0][0]
  st = a[0][1]
  for i in range(1,len(a)):
    if gl<=a[i][1]:
      ans += 1
      gl = a[i][0]
print(ans)

Submission status: Wrong Answer

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

d.sort()
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        p = min(p,d[i][1])
    else:
        ans -= 1
        p = d[i][1]
print(ans)

Submission status: Wrong Answer

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

ans = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    ans[i][1]=(x[i]+l[i])
    ans[i][0]=max(0,x[i]-l[i])
ans.sort()
print(ans)
count=1
j=0
for i in range(n-1):
    
    if ans[j][1]<=ans[i+1][0] :
        count+=1
        j=i+1
    else:
        if ans[j][1]>ans[i+1][1]:
           j=i+1  
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 1
d = {}
for i in range(n):
  x,l = map(int, input().split())
  d[x+l] = x-l
if n == 1:
  print(ans)
else:
  s = list(d.keys())
  s.sort()
  gl = s[0]
  st = d[s[0]]
  for i in s[1:]:
    if gl<=d[i]:
      ans += 1
      gl = i
print(ans)

Submission status: Wrong Answer

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

d.sort(key=lambda x:x[0],reverse=False)
p = d[0][1]
ans = n
for i in range(1,n):
    if d[i][0] <= p:
        ans -= 1
        p = d[i][1]
    else:
        p = min(p,d[i][1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
w=[]
for i in range(n):
    x,l=map(int,input().split())
    w.append([x-l,x+l])
w=sorted(w)
max=w[0][1]
ans=0
for i in range(1,n):
    if w[i][0]<max:
        ans+=1
    else:
        max=w[i][1]
print(len(w)-ans)

Submission status: Wrong Answer

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

d.sort(key=lambda x:x[0],reverse=False)
p = d[0][1]
ans = 1
for i in range(1,n):
    if d[i][0] > p:
        ans += 1
        p = d[i][1]
    else:
        p = min(p,d[i][1])
print(ans)

Submission status: Wrong Answer

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

ans = n
last = -1e10
for r, l in R:
    if last >= l:
        ans -= 1
    else:
        last = r
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    res = 1
    tmp = R[0][0]
    for i in range(1, N):
        if tmp <= R[0][1]:
            res += 1
            tmp = R[i][0]

    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[]
for i in range(s):
    u,l=map(int,input().split())
    t.append((u-l,u+l-1))
t.sort(key=lambda x: x[1])
d=-10*10
ans=0
for i in range(s):
  if d<t[i][0]:
    ans+=1
    d=t[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = []
for i in range(N):
    x, l = map(int, input().split())
    D.append([x-l, x+l])
from operator import itemgetter
D = sorted(D, key = itemgetter(1))
u = -10**10 #最小値:x = 0, l = 10**10の時
cnt = 0
for a, b in D:
    if u < a:
       cnt += 1
       u = b #つぎのロボットの範囲の下限に置きかえる
print(cnt)

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 = 0
prev_r = -10**18
for l, r in data:
    if prev_r >  l:
      continue
    ans += 1
    prev_r = r

print(ans)

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:
    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())
robots = [tuple(map(int,input().split())) for _ in range(N)]

print(robots)
# 最大値と最小値を計算する
robots = [(x+l,x-l) for x,l in robots]
print(robots)
# ソートする
robots.sort()
print(robots)

cnt = 0
last = -float('inf')
for r,l in robots:
    print(last, l, r)
    # 1個前の最大値を、今回の最小値が上回っていたらOK
    if last <= l:
        cnt += 1
        # 次の最大値を更新する
        last = r

print(cnt)

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:
    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:
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, x+l))
Y.sort(key=lambda x: x[0])

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    R = []
    for _ in range(N):
        X, L = map(int, input().split())
        R.append([X, L])
    R.sort()

    res = 1
    tmp = R[0][0] + R[0][1]
    for i in range(1, N):
        ntmp = R[i][0] - R[i][1]
        if tmp <= ntmp:
            res += 1
            tmp = R[i][0] + R[i][1]

    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[]
for i in range(s):
    u,l=map(int,input().split())
    t.append((u-l,u+l-1))
t.sort(key=lambda x: x[1])
d=-10*10
ans=0
for i in range(s):
  a=t[i][0]
  if d<a:
    ans+=1
    d=t[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = []
for i in range(N):
    x, l = map(int, input().split())
    D.append([x-l, x+l])
from operator import itemgetter
D = sorted(D, key = itemgetter(0))
u = -10**10 #最小値:x = 0, l = 10**10の時
cnt = 0
for a, b in D:
    if u < a:
       cnt += 1
       u = b #つぎのロボットの範囲の下限に置きかえる
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import bisect

input = sys.stdin.readline


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

    xlr.sort()

    ans = N
    ma = xlr[0][1]
    for i in range(N - 1):
        if xlr[i + 1][0] < ma:
            ma = min(xlr[i + 1][1], ma)
            ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for i in range(n)]
xl = sorted([[x-l+1,x+l-1] for x,l in xl], key = lambda x: x[1])
now = - 10 ** 10
ans = 0
for s,e in xl:
  if s > now:
    ans += 1
    now = e
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=[None]*n
for i in range(0,n):
    flag=True
    x,l=map(int, input().split())
    li[i]=(x-l, x+l)
li=sorted(li)
for i in range(n):
    if li[i] == None:
        continue
    x, y = li[i]
    index=[]
    for j in range(i+1,n):
        x2,y2 = li[j]
        if y <= x2:
            break
        index.append(j)
    if 1 == len(index):
        li[index[0]] = None
    elif 2 <= len(index):
        li[i]=None
print(len(li) - li.count(None))

Submission status: Wrong Answer

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for i in range(n)]
xl = sorted([[x-l+1,x+l-1] for x,l in xl], key = lambda x: x[1])
print(xl)
now = - 10 ** 10
ans = 0
for s,e in xl:
  if s > now:
    ans += 1
    now = e
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

xl = []

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

itv = []

for i in range(N):
    right = xl[i][0] + xl[i][1]  ##right
    left = xl[i][0] - xl[i][1]  ##left   
    itv.append([right,left])
itv.sort()

ass = 0
tt = -1e10
for i in range(N):
    if tt < itv[i][1]:
        ass += 1
        tt = itv[i][0]
print(ass)

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 = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 < l:
        cnt += 1
        r0 = r
print(cnt)

Submission status: Wrong Answer

Solution code:
def acinput():
    return list(map(int, input().split(" ")))

N=int(input())
bars=[]
for i in range(N):
    tmp = acinput()
    tmp.extend([tmp[0]-tmp[1],tmp[0]+tmp[1]])
    bars.append(tmp)

bars=sorted(bars,key=lambda x:x[3])

print(bars)

count=0
R=-10000000000
for i in range(0,N):

    if R<=bars[i][2]:
        R=bars[i][3]
        count+=1


print(count)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
x = -float("inf")
res = 0
for _ in range(N):
  x, l = map(int, input().split())
  a.append((x - l + 1, x + l - 1))
a.sort(key = lambda x: x[1])
x = -float("inf")
#print(a)
for i in range(N):
  if x < a[i][0]:
    x = a[i][1]
    res += 1
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
robots = [tuple(int(v) - 1 for v in input().split()) for _ in range(n)]

def is_dup(i, j):
    ra, rb = robots[i], robots[j]
    return not (ra[0] + ra[1] < rb[0] - rb[1] or ra[0] - ra[1] > rb[0] + rb[1])

dup = {i: {j: is_dup(i, j) for j in range(i, n)} for i in range(n)}
for i in range(n):
    for j in range(i + 1):
        dup[i][j] = dup[j][i]

dupcnt = dict(sorted([(i, sum(vals.values())) for i, vals in dup.items()], key=lambda d: d[1]))
dkeys = list(dupcnt.keys())

elcnt = 0
while dupcnt[dkeys[-1]] > 1:
    r = dkeys.pop()
    for tr, d in dup[r].items():
        if d:
            dupcnt[tr] -= 1
    elcnt += 1

print(n - elcnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = []
left = []
right = []
for i in range(n):
    x,l = map(int, input().split())
    # num , left , right
    d.append([i,x-l,x+l])

d.sort(key=lambda x:x[1],reverse=False)


p_r = 10**10 + 1
p_l = -1 * (10**10 + 1)
ans = 0
flag = True
p = 0
j = 0
for j in range(len(d)):
    i,l,r = d.pop(0)
    if j == 0:
        p_l = l
        p_r = r
        ans += 1
        #j += 1
    else:
        if l > p_r:
            p_l = l
            p_r = r
            ans += 1
        else:
            if r > p_r:
                pass
            else:

                p_l = l
                p_r = r

print(ans)

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[list(map(int, input().split())) for i in range(s)]
t.sort()
d=-10*10
ans=0
for i in range(s):
  a=t[i][0]-t[i][1]
  if d<a:
    ans+=1
    d=a+2*t[i][1]-1
print(ans)

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
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 < l:
        cnt += 1
        r0 = r
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
x = -float("inf")
res = 0
for _ in range(N):
  x, l = map(int, input().split())
  a.append((x - l, x + l - 1))
a.sort(key = lambda x: x[1])
x = -float("inf")
#print(a)
for i in range(N):
  if x <= a[i][0]:
    x = a[i][1]
    res += 1
print(res)

Submission status: Wrong Answer

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

d.sort(key=lambda x:x[1],reverse=False)


p_r = 10**10 + 1
p_l = -1 * (10**10 + 1)
ans = 0
flag = True
p = 0
j = 0
for j in range(len(d)):
    i,l,r = d.pop(0)
    if j == 0:
        p_l = l
        p_r = r
        ans += 1
        #j += 1
    else:
        if l >= p_r:
            p_l = l
            p_r = r
            ans += 1
        else:
            if r >= p_r:
                pass
            else:

                p_l = l
                p_r = r

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
xl = [list(map(int, readline().decode('utf-8').split())) for _ in range(n)]
LR = [(x - l, x + l) for x, l in xl]
LR.sort()

acc = -10**18

cnt = 0

for l, r in LR:
    if acc > l:
        continue
    cnt += 1
    acc = r

print(cnt)

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 = 0
prev_r = -10**18
for i in range(n):
    if prev_r >  data[i][0]:
      continue
    ans += 1
    prev_r = data[i][1]

print(ans)

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(key=lambda x:x[1])
a=0
r=xl[0][1]
for i in range(N-1):
  if r>xl[i+1][0]:
    if i==N-2:
      a+=1
    else:
      if xl[i+1][1]<xl[i+2][0]:
        a+=1
        r=xl[i+1][1]
      else:
        a+=1
  else:
    r=xl[i+1][1]

    
print(N-a)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
a = []
x = -float("inf")
res = 0
for _ in range(N):
  x, l = map(int, input().split())
  a.append((x - l + 1, x + l))
a.sort(key = lambda x: x[0])
x = -float("inf")
#print(a)
for i in range(N):
  if x < a[i][0]:
    x = a[i][1]
    res += 1
print(res)

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 - 1), (X - L + 1)))
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
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
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 < l:
        r0 = r
    else:
        cnt += 1
        if r0 >= r:
            r0 = r
print(n-cnt)

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[list(map(int, input().split())) for i in range(s)]
t.sort()
d=-10*10
ans=0
for i in range(s):
  if d<t[i][0]-t[i][1]:
    ans+=1
    d=t[i][0]+t[i][1]-1
print(ans)

Submission status: Wrong Answer

Solution code:
# N個のロボット
N = int(input())



# ロボットの設置位置を入力
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

#ソート
X.sort()

# 何個消したか
rem = 0

# 1個前
bx = 0
bl = 0
for i in range(N):
    
    x = X[i][0]
    l = X[i][1]
    #rint(x, l)
    
    # 1個前と重複確認
    if i != 0:
        
        # 1個前と比べて、範囲が重複してなければOK
        #rint(bx - bl+1 , bx , bx+bl-1 , x-l+1 , x , x+l-1)
        # 1個前の方が小さい時                       
        if (bx - bl <= bx <= bx+bl-1 < x-l<= x <= x+l-1) or (bx - bl+1 <= bx <= bx+bl-1 < x-l+1<= x <= x+l-1):
            # 1個前を更新
            bx = x
            bl = l
        else:
            #print("rem")
            rem +=1
            # 1個前は変えないで次へ
            continue

    else:
        # 1個前を更新
        bx = x
        bl = l
    

print(N-rem)

Submission status: Wrong Answer

Solution code:
# N個のロボット
N = int(input())



# ロボットの設置位置を入力
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

#ソート
X.sort()

# 何個消したか
rem = 0

# 1個前
bx = 0
bl = 0
for i in range(N):
    
    x = X[i][0]
    l = X[i][1]
    #rint(x, l)
    
    # 1個前と重複確認
    if i != 0:
        
        # 1個前と比べて、範囲が重複してなければOK
        #rint(bx - bl+1 , bx , bx+bl-1 , x-l+1 , x , x+l-1)
        # 1個前の方が小さい時
        if (bx - bl <= bx <= bx+bl-1 < x-l<= x <= x+l-1):
            # 1個前を更新
            bx = x
            bl = l
        else:
            #print("rem")
            rem +=1
            # 1個前は変えないで次へ
            continue

    else:
        # 1個前を更新
        bx = x
        bl = l
    

print(N-rem)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

N = int(input())
a = [0]*(N)
for i in range(N):
  a[i] = input().split()

#print("a: ",a)
#print("N: ",N)

ii =1
for i in range(N):
  if ii == 1:
#    print("pass a")
    ii +=1
  else:
    jj = 0
#    print("aa")
#    print("ii: ",ii)
    for j in range(ii-1):
      if (int(a[ii-1][0]) + int(a[ii-1][1])) <= (int(a[jj+1][0]) - int(a[jj+1][1])) or (int(a[ii-1][0]) - int(a[ii-1][1])) >= (int(a[jj+1][0]) + int(a[jj+1][1])):
        pass
#        print("pass")
      else:
#        print((int(a[ii-1][0]) + int(a[ii-1][1])),">=",(int(a[jj+1][0]) - int(a[jj+1][1])))
#        print((int(a[ii-1][0]) - int(a[ii-1][1]))," >=", (int(a[jj+1][0]) + int(a[jj+1][1])))
#        print("tyohuku")
        N -= 1
#        jj+=1
        break
      jj+=1
    ii+=1
print(N)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x, l))
r.sort(key=lambda _x: _x[1])
# print(r)
used = set()
cnt = 0
for ri in r:
    arm = set(range(ri[0] - ri[1] + 1, ri[0] + ri[1]))
    # print(ri, used, arm, arm & used)
    if len(arm & used) > 0 and len(used) != 0:
        continue
    used |= arm
    cnt += 1
print(cnt)