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())
XL = []
for i in range(N):
    x,l = map(int,input().split())
    XL.append((x-l+1,x+l-1))

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

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

Submission status: Wrong Answer

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


N = int(input())
XL = [[int(i) for i in input().split()] for i in range(N)] 

count = N
#line = [0] * (2*(10**9) +1)

XL = sorted(XL)
premax = XL[0][0]+XL[0][1]

for i in range(1, N):
    if premax > XL[i][0] - XL[i][1]:
        count -= 1
        if XL[i][0] > XL[i-1][0]:
            continue
        else:
            pass
    premax = XL[i][0]+XL[i][1]

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [[int(i) for i in input().split()] for _ in range(n)]

l = []
ll = []
for i in p:
    ll.append(i[0]-i[1])
    ll.append(i[0]+i[1])
    l.append(ll)
    ll = []

l.sort(key=lambda x:x[0])
#print(l)                                                                      
s = -1000000001
c = 0
for i in l:
    if i[0] >= s:
        s = i[1]
    else:
        c+=1
print(n-c)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=sorted([list(map(int,input().split())) for _ in range(n)])
ans=n
ch=[True]*n
"""
if x[0][0]+x[0][1]>=x[1][0]:
    ch[0]=True
    ans-=1
"""
for i in range(1,n-1):
    if (x[i][0]+x[i][1]>x[i+1][0]-x[i+1][1] and ch[i+1]) or\
         (x[i][0]-x[i][1]<x[i-1][0]+x[i-1][1] and ch[i-1]):
        ans-=1
        ch[i]=False

if ch[n-1] and x[n-1][0]-x[n-1][1]<x[n-2][0]+x[n-2][1]:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
#A=[int(x) for x in input().split()]
XL=[]
for i in range(N):
    XL.append(list(map(int,list(input().split()))))
XL=np.asarray(XL)
XLs=XL[np.argsort(XL[:,0])]
right=XLs[0][0]+XLs[0][1]
ans=1
for i in range(N-1):
    if XLs[i+1][0]-XLs[i+1][1]-right>=0:
        ans+=1
        right=XLs[i+1][0]-XLs[i+1][1]
        
#ans=XLs
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
a = sorted(a, key=(lambda x:x[0]))
aa = sorted(a, key=(lambda x:x[0]), reverse=True)

cnt1 = 0
cnt2 = 0

max_n1 = sum(a[0])
max_n2 = sum(aa[0])

for point, area in a[1:]:
    i = point-area
    if max_n1 > i:
        cnt1 += 1
    else:
        max_n1 = point+area

for point, area in aa[1:]:
    i = point-area
    if max_n2 > i:
        cnt2 += 1
    else:
        max_n2 = point+area

print(max(N-cnt1, N-cnt2))

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:
        if m[num][1] > m[num + 1][0]:
            cnt += 1
            if num < n-2 and m[num][1] > m[num + 2][0]:
                num -= 1
            num += 1

        num += 1
    print(n-cnt)


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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
import copy
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_list = []
for i in range(N):
    tmp_sort_list = copy.deepcopy(sort_robot_list)
    del tmp_sort_list[i]
    minus_count = 1
    for before_value, after_value in zip(tmp_sort_list, tmp_sort_list[1:]):
        if before_value[1] >= after_value[0]:
            minus_count += 1

    if i < N - 1:
        if sort_robot_list[i][1] <= sort_robot_list[i + 1][0]:
            minus_count -= 1

    minus_count_list.append(minus_count)

print(len(sort_robot_list) - min(minus_count_list))

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 - 1):
  k = k
  if (X_L_list[i + 1][0] - X_L_list[k][0]) < (X_L_list[k][1] + X_L_list[i + 1][1]):
    j = j + 1
  else:
    k = i + 1


print(N - j)

Submission status: Wrong Answer

Solution code:
'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''
'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''
'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''
'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''
'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
'''
リスト同士の演算
list(map(lambda x, y: x+y, el2, el3))
'''
'''
配列の初期化
配列名=[a]*n+[b]*m
'''
'''
重複
list(set())
２次元配列
list(map(list, set(map(tuple, addition))))
'''
'''
順列
for el in itertools.permutations(配列のパターン):
'''
'''
Decimal()
'''
# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()




from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul
def gcd(*numbers):
    return reduce(math.gcd, numbers)


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


N = int(stdin.readline().rstrip())
Xs = []
Ls = []
Ran = []
for k in range(N):
    tmp = stdin.readline().rstrip().split()
    Xs.append(int(tmp[0]))
    Ls.append(int(tmp[1]))
    before = int(tmp[0]) - int(tmp[1])
    after = int(tmp[0]) + int(tmp[1])
    Ran.append([before, after, int(tmp[0])])
sorted_data = sorted(Ran, key=lambda x: (x[2]))
Ran = sorted_data
count = 0
posAfter = Ran[0][1]
numP = 0
numT = 1
while True:
    if numP == len(Ran):
        break
    if numT == len(Ran):
        break
    nextBefore = Ran[numT][0]
    if nextBefore < posAfter:
        count += 1
        numT += 1
    else:
        numP = numT
        numT = numP+1
        posAfter = Ran[numP][1]
print(N-count)

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
    tmp = min(tmp, x+l)

print(n-res)

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]:
    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:
N = int(input())
X = list(list(map(int,input().split())) for _ in range(N))
X.sort()
check = N
ans = 0
for i in range(N):
    for j in range(1, N-1):
        # print(X[i][0] + X[i][1], X[j][0] - X[j][1])
        if X[i][0] + X[i][1] <= X[j][0] - X[j][1]:
            pass
        else:
            check -= 1
    ans = max(check, ans)
print(ans)

Submission status: Wrong Answer

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

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

lr = sorted(lr)

remove = 0
skip = False

for i in range(1, n):
    if skip:
        skip = False
    elif lr[i - 1][0] == lr[i][0]:
        remove += 1
        skip = True
    elif lr[i - 1][0] < lr[i][0] < lr[i - 1][1]:
        remove += 1
        skip = True

print(n - remove)

Submission status: Wrong Answer

Solution code:
n = int(input())

d = {}
for i in range(n):
  t1, t2 = map(int, input().split())
  d[t1] = t2

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

i = 0
c = 0
while i < n-1:
  y1 = d[i][0] + d[i][1]
  y2 = d[i+1][0] - d[i+1][1]
  if y2 < y1:
    c += 1
    i += 1
  i += 1

print(n-c)

Submission status: Wrong Answer

Solution code:
N = int(input())
XL = []
for n in range(N):
    XL.append([int(x) for x in input().split()])
XL = sorted(XL, key=lambda x:(x[0],x[1]))
m = -float("inf")
ans = 0
for n in range(N):
    if XL[n][0]-XL[n][1] >= m:
        ans += 1
        m = XL[n][0]+XL[n][1]
print(ans)

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:
            if robots[i][1] > robots[i+1][1]:
                robots[i][-1] = True
            elif robots[i][1] < robots[i+1][1]:
                robots[i+1][-1] = True
            else:
                lnum = 0
                rnum = 0
                for robot in robots:
                    if robot[0] == robots[i][0] + robots[i][1] - 1:
                        lnum += 1
                    if robot[0] == robots[i][0] - robots[i][1] + 1:
                        lnum += 1
                    if robot[0] == robots[i+1][0] + robots[i+1][1] - 1:
                        rnum += 1
                    if robot[0] == robots[i+1][0] - robots[i+1][1] + 1:
                        rnum += 1
                if lnum > rnum:
                    robots[i][-1] = True
                else:
                    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())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a-b+1,i])
    l.append([a+b,i])
l.sort()
re=0
c=[0]*n
f=0
mf=0
di=set([])
for i in range(n*2):
    p=l[i][0]
    j=l[i][1]
    if c[j]==0:
        c[j]+=1
        f+=1
        mf=max(mf,f)
        #di.add(j)
    else:
        f-=1 
        if f==0:
            re+=mf-1
        mf=0
            
        #f=0
print(n-re)

Submission status: Wrong Answer

Solution code:
n=int(input())
temp = [input() for _ in range(n)]
x = [0]*n
l = [0]*n
for i in range(n):
  x[i],l[i] = map(int, temp[i].split())
temp2 = zip(x,l)
x,l = zip(*sorted(temp2))
x = list(x)
l = list(l)
result=n
for j in range(n-1):
  if x[j]+l[j]>x[j+1]-l[j+1]:
    if j!=(n-2) :
      if x[j+1]+l[j+1]>x[j+2]-l[j+2]:
        result-=1
        x[j+1]=0
        l[j+1]=0
      else:
        result-=1
        x[j]=0
        l[j]=0
    else:
      result-=1
      x[j]=0
      l[j]=0
print(result)

Submission status: Wrong Answer

Solution code:
import bisect

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

data.sort()

l, x = data[0]
touched = [-2 * 10 ** 9 - 1, 2 * 10 ** 9 + 1]
count = 0
for i in range(N):
	l, x = data[i]
	p_l = x - l + 1
	p_r = x + l - 1
	i1 = bisect.bisect_left(touched, p_l) - 1
	i2 = bisect.bisect_right(touched, p_r)
	if i1 + 1 == i2 and i1 % 2 == 0:
		touched.insert(i1 + 1, p_r)
		touched.insert(i1 + 1, p_l)
		count += 1

print(count)

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: student[0] + 100000000000000000000 * student[1])


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


print(now)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())

xl = []
for _ in range(n):
    x, l = map(int, input().split())
    xl.append([x, l, True])
xl.sort()

cnt = 0
for i in range(n-1):
    x, l, f = xl[i]
    if not f:
        continue
    c = x + l - 1
    for j in range(i+1, n):
        x1, l1, f1 = xl[j]
        if not f1:
            continue
        if c < x1 - l1 + 1:
            continue
        
        if l > l1:
            xl[i][2] = False
        else:
            xl[j][2] = False
        cnt += 1

print(n - cnt)

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])
ll.sort()  
tf=[]
for i in range(n-1):
  if ll[i][0]+ll[i][1]-1 > ll[i+1][0]-ll[i+1][1]+1:
    tf.append(False)
  else:
    tf.append(True)
print(n-tf.count(False))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
l = []
c = []
d = {}
same = 0
bef = -1
bef_l = -1
ans = 0
min_same = 0

for i in range(n):
    xx,ll = map(int, input().split())
    if i > 0:
        if bef == xx:
            same += 1
            min_same = min(min_same,ll)
        else:
            ans += same
            if same > 0:
                d[bef] = min_same
            else:
                d[bef] = bef_l
            same = 0
    bef = xx
    bef_l = ll
ans += same
if same > 0:
    d[bef] = min_same
else:
    d[bef] = bef_l

dct = sorted(d.items())

f = 0
same = 0
for i in range(1,len(dct)):
    if dct[i][0] == dct[i-1][0]:
        ans += 1
    elif dct[i][0]-dct[i-1][0] < dct[i][1]+dct[i-1][1]:
        f += 1
    else:
        ans += (f+1)//2
        f = 0


if f != 0:
    ans += (f+1)//2

print(n-ans)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7
n=int(input())
xl=[list(map(int,input().split())) for i in range(n)]
from collections import deque
# for i in range(n):
#     right.append(xl[i][0]+xl[i][1])
#     left.append(xl[i][0]-xl[i][1])
ans=0
xl.sort()
# right.sort()
# left.sort()
d=deque(xl)
while d:
    tmp=d.popleft()
    # print(tmp)
    # print(d)
    while d:
        if tmp[0]+tmp[1]>d[0][0]-d[0][1]:
            ans+=1
            if tmp[0]+tmp[1]<d[0][0]+d[0][1]:
                d.popleft()
                break
            else:
                break
        else:
            break
if n==1:
    print(1)
    quit()

print(n-ans)

Submission status: Wrong Answer

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

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


for i in range(n-1):
    if list[i][0] + list[i][1] > list[i+1][0] - list[i+1][1]:
        if not(list[i][0] in ans):
            ans.append(list[i+1][0])
        elif list[i-1][0] + list[i-1][1] > list[i+1][0] - list[i+1][1]:
            ans.append(list[i+1][0])
print(n - len(ans))

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+1,x+l-1))

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

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

Submission status: Wrong Answer

Solution code:
s=int(input())
t=[list(map(int, input().split())) for i in range(s)]
t.sort()
a=t[0][0]+t[0][1]
b=1
c=0
count1=1
count2=0
for i in range(1,s):
  c=t[i][0]-t[i][1]
  if a<=c:
    count1+=1
    a=t[i][0]+t[i][1]
a=t[0][0]+t[0][1]
d=0
for j in range(1,s):
  c=t[j][0]-t[j][1]
  if d==0:
    if a<=c:
      a=t[j][0]+t[j][1]      
      continue
    else:
      a=t[j][0]+t[j][1]
      count2+=1
      d+=1
  else:
    if a<=c:
      count2+=1
      a=t[i][0]+t[i][1]
if count1<count2:
  print(count2)
else:
  print(count1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [[0,0] for _ in range(n)]

for i in range(n):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
cnt=0
temp=1
for i in range(n-1):
    if a[i+temp-cnt][0]-a[i+temp-cnt][1]<a[i-cnt][0]+a[i-cnt][1]:
        cnt+=1
        temp+=1
    else:
        temp=1
print(n-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

robots = []

for _ in range(N):
    x_l = list(map(lambda x: int(x), input().split(" ")))
    x = x_l[0]
    l = x_l[1]
    robots.append((x-l, x+l, l))

place = -float("inf")
minus_count = 0
temp_l = -float("inf")

for robot in sorted(robots):
    if robot[0] < place:
        minus_count += 1
        if robot[2] >= temp_l:
            pass
        else:
            place = robot[1]
            temp_l = robot[2]
    else:
        place = robot[1]
        temp_l = robot[2]

result = N - minus_count

place = float("inf")
minus_count = 0
temp_l = float("inf")

for robot in reversed(sorted(robots)):
    if robot[1] > place:
        minus_count += 1
        if robot[2] >= temp_l:
            pass
        else:
            place = robot[0]
            temp_l = robot[2]
    else:
        place = robot[0]
        temp_l = robot[2]

temp_result = N - minus_count

if temp_result > result:
    result = temp_result

print(result)

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]
idx = 0

for i in range(1, n):
    n_s = dic[i][0]+dic[i][1]
    if pre > n_s:
        pre = n_s
        idx = i

ans = 1

for i in range(idx, 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:
n=int(input())
x=[0]*n
l=[0]*n
for i in range(n):
    x[i],l[i]=list(map(int,input().split()))

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


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


print(cnt)

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, 1))

res = 0
i = 0
while i < N:
    if i + 1 < N and sum(XL[i]) > XL[i + 1][0] - XL[i + 1][1]:
        if sum(XL[i]) < XL[i + 1][0] + XL[i + 1][1]:
            res += 1
        i += 1
    else:
        res += 1
    i += 1

print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
n = int(input().rstrip())
s = 0
d = 0
e = min(n-2,3)
hanni = sorted([[int(x) for x in input().rstrip().split()] for _ in range(n)], key=lambda x: (x[1], x[0]))
for _ in range(n):
  if s != len(hanni)-1 and hanni[s][1] > hanni[s+1][0]:
    d += 1
    if d>=e:
      del hanni[s]
      d = 0
    else:
      s+=1
  else:
    s+=1
    d = 0
    
print(len(hanni))

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+1,x+l-1))

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

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:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XL):
    ans = 0
    XL.sort(key=lambda x: x[0])
    XL.sort(key=lambda x: x[1])


    p = []
    s = []
    for x, l in XL:
        lp, rp = x-l+1, x+l-1
        s.append((lp, rp))
        p.append(lp)
        p.append(rp)
    p.sort()
    d = {}
    for i, v in enumerate(p):
        d[v] = i

    ans = 0
    a = [0] * len(p)
    for lp, rp in s:
        l = d[lp]
        r = d[rp]
        for i in range(l, r+1):
            if a[i] != 0:
                break
        else:
            ans += 1
            for i in range(l, r+1):
                a[i] = 1
    return ans


def main():
    N = read_int()
    XL = [read_int_n() for _ in range(N)]
    print(slv(N, XL))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
for i in range(n):
    x,y= map(int,input().split())
    res = [x-y+1+100000000000,x+y-1+100000000000]
    arr.append(res)
arr.sort()
if n==1:
    print(n)
else:
    end = arr[0][1]
    mini = 0
    for i in range(1,n):
        if arr[i][0] <= end:
            end = min(end,arr[i][1])
            mini+=1
        else:
            end =arr[i][1]
    print(n-mini)

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)
print(new_grid)
cnt = 0
for i in range(n-1):
    if i + 1 >= len(new_grid):
        break;
    if new_grid[i][1] > new_grid[i+1][0]:
        cnt += 1
        del new_grid[i+1]

ans = n - cnt

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
ans=1
B=[]
for j in range(n):
    B.append([A[j][0]-A[j][1],A[j][0]+A[j][1]])

B=sorted(B)
point=B[0][1]
for i in range(1,n):
    if point>B[i][0]:continue
    elif point<=B[i][1]:
        ans +=1
        point=B[i][1]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

robots = []

for _ in range(N):
    x_l = list(map(lambda x: int(x), input().split(" ")))
    x = x_l[0]
    l = x_l[1]
    robots.append((x-l, x+l, l))

place = -float("inf")
minus_count = 0
temp_l = -float("inf")

for robot in sorted(robots):
    if robot[0] < place:
        minus_count += 1
        if robot[2] > temp_l:
            pass
        else:
            place = robot[1]
            temp_l = robot[2]
    else:
        place = robot[1]
        temp_l = robot[2]

result = N - minus_count

place = float("inf")
minus_count = 0
temp_l = float("inf")

for robot in reversed(sorted(robots)):
    if robot[1] > place:
        minus_count += 1
        if robot[2] >= temp_l:
            pass
        else:
            place = robot[0]
            temp_l = robot[2]
    else:
        place = robot[0]
        temp_l = robot[2]

temp_result = N - minus_count

if temp_result > result:
    result = temp_result

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([list(map(int, input().split())) for _ in range(n)])
r = a[0][0]+a[0][1]-1
l = 0
for j in range(1,n):
    i = a[j]
    l = i[0]-i[1]+1
    if r < l:
        r = i[0]+i[1]-1
    else:
        n -= 1
        r = min(r,i[0]+i[1]-1)
print(n)

Submission status: Wrong Answer

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

X = [xl[0] for xl in XL]
L = [xl[1] for xl in XL]

i = 0
count = N
while i < count - 1:
  if X[i] + L[i] > X[i+1] - L[i+1]:
    if X[i] + L[i] < X[i+1] + L[i+1]:
      del X[i+1]
      del L[i+1]
    else:
      del X[i]
      del L[i]
    count -= 1
  else:
    i += 1
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
xl = [list(map(int,input().split())) for i in range(n)]
xl.sort()
i=0
while i<len(xl)-1:
  memo=[]
  for j in range(i+1,len(xl)):
    if xl[i][0]+xl[i][1]>xl[j][0]-xl[j][1]:
      memo.append(xl[j])
  if len(memo)>0:
    for j in memo:
      xl.remove(j)
  i += 1
print(len(xl))

Submission status: Wrong Answer

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

ans2 = 1
x, l = xls[-1]
for i in range(n-1):
    nx, nl = xls[-2-i]
    if x-l+1<nx+nl: continue
    ans2 += 1
    x, l = nx, nl
print(min(ans1, ans2))

Submission status: Wrong Answer

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

x0,l0 = l[0][0],l[0][1]
y = x0 + l0
count = 1
for i in range(n-1):
  x,d = l[i+1][0],l[i+1][1]
  z = x - d
  
  if z >= y:
    y = x + d
    count = count + 1
  else:
    continue
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=[]
for i  in range(n):
    x,y=map(int,input().split())
    lists.append((x-y,x+y))
lists=sorted(lists,key=lambda x:(x[0],x[1]))
A=1
P=lists[0]
#貪欲法
for i in range(1,len(lists)):
    if lists[i][0]>=P[1]:
        A+=1
        P=lists[i]
print(A)

Submission status: Wrong Answer

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

cnt=0
max_n = sum(a[0])

for point, area in a[1:]:
    i = point-area
    if max_n > i:
        cnt += 1
    else:
        max_n = point+area
print(N-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 1
a = []

for i in range(N):
    tmpa, tmpb = map(int,input().split())
    a.append([tmpa-tmpb, tmpa+tmpb])

a.sort()

tmp = a[0]
for i in range(1,N):
    if a[i][1] > tmp[1] and a[i][0] >= tmp[1]:
        tmp = a[i]
        ans += 1

    if a[i][1] < tmp[1] and a[i][0] >= tmp[1]:
        tmp = a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
from collections import defaultdict
d = defaultdict(list)
X = []
xl = [tuple(map(int,input().split())) for i in range(n)]
for x,l in xl:
    d[x].append(x-l)
    d[x].append(x+l)
    X.append(x)

X.sort()

i = 1

while len(X)>i:
    x_1 = X[i-1]
    x_2 = X[i]
    min_1 , max_1 = d[x_1]
    min_2 , max_2 = d[x_2]

    if max_1 > min_2:
        if max_2 >= max_1:
            d.pop(x_2, None)
            d.pop(x_2, None)
            i += 1
        else:
            d.pop(x_1, None)
            d.pop(x_1, None)
    i += 1
ans = len(d)
print(ans)

Submission status: Wrong Answer

Solution code:
X = []
L = []
N = int(input())
for i in range(N):
    a,b = input().split()
    a = int(a)
    b = int(b)
    X.append(a)
    L.append(b)
X_range = []
for i in range(N):
    a = []
    a.append(X[i] - L[i])
    a.append(X[i]+L[i])
    X_range.append(a)
count = 100
print(X_range)
while count != 0:
    t_count = [0 for i in range(N)]
    count = sum(t_count)
    for i in range(N):
        for t in range(N):
            if X_range[i][0]< X_range[t][0] and X_range[t][0] < X_range[i][1]:
                t_count[t] += 1
            if X_range[i][0]< X_range[t][1] and X_range[t][1] < X_range[i][1]:
                t_count[t] += 1
    max_index =  t_count.index(max(t_count))
    if not count == 0:
        del X_range[max_index]
    N -= 1


    t_count = [0 for i in range(N)]
    for i in range(N):
        for t in range(N):
            if X_range[i][0]< X_range[t][0] and X_range[t][0] < X_range[i][1]:
                t_count[t] += 1
            if X_range[i][0]< X_range[t][1] and X_range[t][1] < X_range[i][1]:
                t_count[t] += 1
    count = sum(t_count)
print(len(X_range))

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])

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

Submission status: Wrong Answer

Solution code:
N = int(input())
arm_x = {}
for _ in range(N):
    inp = list(map(int, input().split()))
    arm_x[inp[0]] = inp[1]
dic = sorted(arm_x.items(), key=lambda x:x[0])
ans = N
i = 0
while i <N:
    temp = 0
    for j in range(i+1,N):
        if dic[i][0]+dic[i][1]> dic[j][0]-dic[j][1]:
            ans -= 1
            temp += 1
        else:
            break
    i += 1+temp
ans2 = N
i = N-1
while i>0:
    temp = 0
    for j in reversed(range(i-1)):
        if dic[i][0]-dic[i][1] < dic[j][0]+dic[j][1]:
            ans -= 1
            temp += 1
        else:
            break
    i -= 1+temp
print(min(ans,ans2))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[[int(i) for i in input().split()] for i in range(n)]

l.sort()

left=[]
right=[]
count=0

for i in l:
  left.append(i[0]-i[1])
  right.append(i[0]+i[1])
  if len(right)>1:
    if left[-1]<right[-2]:
      right=right[:(-1)]
      left=left[:(-1)]
    else:
      count+=1
  else:
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
arr = []
for i in range(n):
    x,y= map(int,input().split())
    res = [x-y+1+100000000000,x+y-1+100000000000]
    arr.append(res)
arr.sort()
if n==1:
    print(n)
else:
    end = arr[0][1]
    mini = 0
    for i in range(1,n):
        if arr[i][0] < end:
            end = min(end,arr[i][1])
            mini+=1
        else:
            end =arr[i][1]
    print(n-mini)

Submission status: Wrong Answer

Solution code:
import numpy as np

stdin = np.fromstring(open(0).read(), np.int64, sep=' ')
N = stdin[0]
XL = stdin[1:].reshape(-1, 2).T
x = XL[0]
l = XL[1]
arg = np.argsort(x)
x = x[arg]
l = l[arg]

xr = x + l
xl = x - l

count = 0
i = 0
while i < N - 1:
    for j in range(i + 1, N):
        if xr[i] >= xl[j]:
            count += 1
        else:
            i = j
    else:
        break
print(N - count)