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())
x = []
l = []
xl = []
for i in range(n):
    x1, l1 = map(int, input().split())
    xl.append([x1, x1 + l1, 2 * l])
xl.sort()
ans = n
for i in range(n - 1):
    if xl[i][1] > xl[i + 1][0]:
        if xl[i][2] >= xl[i + 1][2]:
            ans -= 1
        else:
            ans -= 1
            xl[i + 1] = [i]
print(ans)

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 = 0
for i in range(1,N):
    if M >= XL[i][0]-XL[i][1]:
        ans += 1
    else:
        M = XL[i][0]+XL[i][1]-1
print(N-ans)

Submission status: Wrong Answer

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

temp = [x for x in range(n)]
arr = []
ans = 0
cnt = 0
li.sort()

while True:
    check = -10**10
    for i in temp:
        s = li[i][0] - li[i][1]
        if check > s:
            if i-1 not in arr:
                arr.append(i-1)
            if i not in arr:
                arr.append(i)
        check = li[i][0] + li[i][1]
    else:
        if len(arr) == 0:
            break
        temp = arr
        t = -2
        for index,i in enumerate(arr):
            if t == -2:
                t = i
            elif t+1 == i:
                t = i
                continue
            else:
                ans += 1
                del temp[index-2]
        else:
            ans += 1
            del temp[-2]
        arr = []

print(n-ans)

Submission status: Wrong Answer

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

ppair.sort()
ans = 0
pf = False
for i in range(N-1):
    if (pf):
        pf = False
        continue
    else:
        if (sum(ppair[i]) > ppair[i+1][0] - ppair[i+1][1]):
            ans += 1
            pf = True

print(N-ans)

Submission status: Wrong Answer

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

N = int(input())
robot_number = N
XL = {}
for n in range(N):
    [x, l] = [int(i) for i in input().split()]
    XL[x] = l

#available_positions = {}
#for i in range(-1000, 1000):
#    available_positions[i] = 0
used_area = []

# 腕の長さでsort
XL_sorted = sorted(XL.items(), key=lambda x:x[1])

# 腕の長さが短いものから見ていって、かぶっていたら削除
for (x, l) in XL_sorted:

    # このロボットの腕の範囲に既にロボットがいるか確認
    flag = False
    #position = x - l + 0
    #while position < x + l - 1:
    #    if available_positions[position] != 0:
    #        flag = True
    #        break
    #    position += 1
    minimum = x-l+1
    maximum = x+l-1
    for (mi, ma) in used_area:
        if minimum <= ma and maximum >= mi:
            flag = True
            break

    if flag is True:
        robot_number -= 1
        continue

    # このロボットの範囲をメモ
    #position = x - l + 0
    #while position < x + l - 1:
    #    available_positions[position] = 1
    #    position += 1
    used_area.append((x-l+1, x+l-1))


print(robot_number)

Submission status: Wrong Answer

Solution code:
N = int(input())
List = dict()
for i in range(N):
    X,L = map(int,input().split())
    List.update({X:L})
keys= sorted(List,reverse=True)
if len(List)<=1:
    print(len(List))
elif len(List)<3:
    if keys[0]-List[keys[0]]<=keys[1] or keys[1]+List[keys[1]]<=keys[0]:
        del List[keys[i]]
    print(len(List))
else:
    for i in range(1, len(keys)-1):
        if keys[i]-List[keys[i]]<=keys[i+1] or keys[i]+List[keys[i]]>=keys[i-1]:
            del List[keys[i]]
    print(len(List))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append({'x': x_tmp, 'l': l_tmp})

robots_sorted = sorted(robots, key=lambda x: x['x'])
ans = n
i = 0
while(i != n-1):
    if((robots_sorted[i]['x'] + robots_sorted[i]['l']) > (robots_sorted[i+1]['x'] - robots_sorted[i+1]['l'])):
        if(i == 0):
            if(robots_sorted[0]['l'] > robots_sorted[1]['l'] * 2):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(i == n-1):
            if(robots_sorted[n-1]['l'] * 2 > robots_sorted[n]['l']):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(robots_sorted[i]['l'] > robots_sorted[i+1]['l']):
            robots_sorted.pop(i)
        else:
            robots_sorted.pop(i+1)
        i += -1
        n += -1
    i += 1

print(n)

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 range_min <= (pos-armlen):
        ans += 1
        range_min = pos+armlen

print(ans)

Submission status: Wrong Answer

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

prev_right = -float("inf")
prev_arm = 0
ans = 0
for i in range(n - 1):
    now_left = xl[i][0] - xl[i][1]
    now_right = xl[i][0] + xl[i][1]
    if prev_right > now_left:
        if now_right > xl[i + 1][0] - xl[i + 1][1]:
            ans += 1
        else:
            if prev_arm > xl[i][1]:
                ans += 1
                prev_right = xl[i][0] + xl[i][1]
                prev_arm = xl[i][1]
            else:
                ans += 1
    else:
        prev_right = xl[i][0] + xl[i][1]
        prev_arm = xl[i][1]

i = n - 1
now_left = xl[i][0] - xl[i][1]
if prev_right > now_left:
    ans += 1

print(n - ans)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

x.sort()

remove = 0
flag = True

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1][0] - x[k][0]) > x[k][1] + x[k+1][1] and x[k+1][0]>0 and x[k][0]>0:
        remove +=1
        x[k+1][0] = -1
       	flag =False
        break

    if flag == True:
        break
    
print (n -remove)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = []
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 = 10**9 + 1
ans = 0
while len(d) > 0:
    i,l,r = d.pop(-1)
    #print(i,l,r,p)
    if r >= p:
        ans += 1
    p = l
    #print(d)

print(n-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[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:
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]:
                # print(d.popleft(),1)
                break
            else:
                continue
        else:
            break
if n==1:
    print(1)
    quit()

print(n-ans)

Submission status: Wrong Answer

Solution code:
#python3
import operator as op
n = int(input())
a = []
for _ in range(n):
    x, l = map(int, input().split())
    a.append((x,l))

a.sort(key=op.itemgetter(0))

rmv = 0
i = 0
while i < n-1:
    x1, l1 = a[i]
    x2, l2 = a[i+1]
    iMAX = x1 + l1
    ipls1MIN = x2 - l2
    i+=1
    if iMAX > ipls1MIN:
        rmv += 1
        i+=2

print(n-rmv)

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_X_L = sorted(X_L, key=lambda x: x[0])

    # dupl = [len([]) for i in range(N)]

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

    x_max = - 1e9
    x_min = 2e9

    allowed = []

    for i in range(N):
        i_min = sorted_X_L[i][0] - sorted_X_L[i][1]
        i_max = sorted_X_L[i][0] + sorted_X_L[i][1]

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

    print(len(allowed))


def is_duplicates(range1, range2):
    return range1[1] > range2[0] or range1[0] < range2[1]


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
x_org = []
for i in range(n):
    x_org.append(input().split())

x = sorted(x_org, key=lambda z: int(z[0]))

removed = 0
for i in range(1, n):
    if (int(x[i][0]) - int(x[i][1])) < (int(x[i-1][0]) + int(x[i-1][1])):
        removed += 1
        x[i] = x[i-1]

print(n - removed)

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+1
        else:
            pass
    else:
        now = i+1
    i += 1    


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

Submission status: Wrong Answer

Solution code:
n = int(input())

robots = []

for _ in range(n):
    x, l = map(int, input().split())
    left, right = x-l+1, x+l-1
    robots.append([left, right])

robots.sort()

DP = [0, -float('INF')]

for left, right in robots:
    count, now = DP[0], DP[1]
    if left > now:
        DP = [count+1, right]

    else:
        if right < now:
            DP = [count, right]
        else:
            continue

ans = DP[0]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
xl = []
for _ in range(n):
    x, l = map(int, input().split())
    xl.append((x, l))
xl.sort(key=lambda x:x[0])
i = 0
if n==1:
    print(1)
    sys.exit(0)
while i<len(xl)-1:
    if xl[i][0]+xl[i][1] <= xl[i+1][0]-xl[i+1][1]:
        i += 1
    else:
        del xl[i+1]
print(len(xl))

Submission status: Wrong Answer

Solution code:
N=int(input())

X_t=[]
L_t=[]

for _ in range(N):
    x,l=map(int,input().split())
    X_t.append(x)
    L_t.append(l)

tmp=zip(X_t,L_t)
XL=sorted(tmp)

X=[]
L=[]

for x,l in XL:
    X.append(x)
    L.append(l)
    


del_ls=[]
for i in range(1,N-1):
    if (X[i]+L[i]>X[i+1]-L[i+1]) and (X[i]-L[i]<X[i-1]+L[i-1]):
        del_ls.append(i)
        
del_ls.sort(reverse=True)

while 1:
    if del_ls!=[]:
        del X[del_ls[-1]]
        del L[del_ls[-1]]
        del del_ls[0]
    else:
        break

del_ls2=[]
lenX=len(X)
for i in range(lenX-1):
    if X[i]+L[i]>X[i+1]-L[i+1]:
        del_ls2.append(i)
print(lenX-len(del_ls2))

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.append([x-l,x+l])

ans = n
l,r = 0,1
while r < n and l < n:
    #print(hani[l][0],hani[l][1],hani[r][0],hani[r][1])
    if hani[r][0] < hani[l][1]:
        r += 1
        ans -= 1
    else:
        l = r
        r += 1
    #print(l,r)
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[1])

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

ans = n - cnt

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

x.sort()

remove = 0
flag = True

while(1):
    flag = True
    
    for k in range(n-1):
      if (x[k+1][0] - x[k][0]) > x[k][1] + x[k+1][1]:
        remove +=1
        x[k+1][0] = -1000*k
       	flag =False
        break

    if flag == True:
        break
    
print (n -remove)

Submission status: Wrong Answer

Solution code:
N = int(input())

list_ = list()

for i in range(N):
  X,L = map(int,input().split())
  max_ = min(10**9,X+L)
  min_ = max(0,X-L+1)
  list_.append((min_,X,max_))
list_.sort()

d = 0
nowmax = -1
nowmin = -1

for min_, x, max_ in list_:
  if nowmax >= min_:
    d += 1
    if nowmin >= min_:
      pass
    elif nowmax <= max_:
      pass
    else:
      nowmin = min_
      nowmax = max_
  else:
    nowmin = min_
    nowmax = max_
  
print(N-d)

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]:
        ans -= 1
    else:
        M = XL[i][0]+XL[i][1]-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
xl = []
for i in range(n):
    xl.append(list(map(int, input().split())))
xl.sort()
if n == 1:
    print(0)
    exit()
if n == 2:
    if (xl[1][0] - xl[1][1]) < (xl[0][0] + xl[0][1]):
        print(1)
        exit()
    else:
        print(0)
        exit()
ans = 0
while 3 <= len(xl):
    reps = [0] * len(xl)
    for i in range(0, (len(xl) - 2), 1):
        cnt = 0
        if (xl[i + 1][0] - xl[i + 1][1]) < (xl[i][0] + xl[i][1]):
            cnt += 1
        if (xl[i + 2][0] - xl[i + 2][1]) < (xl[i + 1][0] + xl[i + 1][1]):
            cnt += 1
        reps[i + 1] = cnt
    tmp = []
    add = 0
    for i in range(len(xl)):
        if reps[i] != 2:
            tmp.append(xl[i])
        else:
            add += 1
    if add == 0:
        break
    else:
        ans += add
    xl = tmp

if len(xl) == 2:
    if (xl[1][0] - xl[1][1]) < (xl[0][0] + xl[0][1]):
        print(n - (ans + 1))
        exit()
print(n - ans)

Submission status: Wrong Answer

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

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

s = []
t = []
for r in robos:
    s.append(r[0])
    t.append(r[1])


#
# itv = []
# for i in range(n):
#     itv.append([t[i],s[i]])
# itv.sort()

ass = 0
tt = -100000000000000
for i in range(n):
    if tt < robos[i][0]:
        ass += 1
        tt = robos[i][1]
print(ass)

Submission status: Wrong Answer

Solution code:
n = int(input())
robots = []
for _ in range(n):
    xi, li = map(int, input().split())
    robots.append((xi - li, xi + li))
robots.sort()
cnt = [0] * n
for i in range(1, n):
    nl = robots[i][0]
    nr = robots[i][1]
    ol = robots[i - 1][0]
    oright = 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())
arr = [list(map(int,input().split())) for i in range(N)]
arr = sorted(arr, key=lambda x: x[0])
F = [True]*N
P = [0]*N
for i in range(N):
  P[i] = [arr[i][0]-arr[i][1], arr[i][0]+arr[i][1]]
ind = 0
for i in range(1,N):
  if F[i]:
    if P[i][0] < P[ind][1]:
      F[i] = False
    else:
      ind += 1  
print(F.count(True))

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[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:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    X = []
    L = []
    LX = []
    for i in range(N):
        temp = list(map(int,input().split()))
        LX.append([temp[1],temp[0]])

    LX.sort()

    res = 1
    end = sum(LX[0])

    for i in range(1,N):
        if end < LX[i][1]:
            res += 1
            end = sum(LX[i])

    print(res)



main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

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

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
    print(cnt)

if __name__ == "__main__":
    main()

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
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
        #di.add(j)
    else:
        f-=1
        re+=f
        f=0
print(n-re)

Submission status: Wrong Answer

Solution code:
N=int(input())
XL=sorted([list(map(int,input().split())) for i in range(N)])
l,r,a=-10**9,0,0
for i in range(N):
    r=XL[i+1][0] if i<N-1 else 2*10**9
    if XL[i][0]+XL[i][1]>r or XL[i][0]-XL[i][1]<l:
        a+=1
    else:
        l=XL[i][0]
print(N-a)

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)]
xl = np.array(xl)

cnt = 0
independ_list = []
for (x, l) in xl:
    if len(independ_list) == 0:
        independ_list.append((x - l, x + l))
        cnt += 1
    else:
        flag = True
        for (start, end) in independ_list:
            if (x - l < end) * (start < x + l):
                flag = False

        if flag:
            cnt += 1

cnt_ = 0
independ_list = []
for (x, l) in xl[::-1]:
    if len(independ_list) == 0:
        independ_list.append((x - l, x + l))
        cnt_ += 1
    else:
        flag = True
        for (start, end) in independ_list:
            if (x - l < end) & (start < x + l):
                flag = False
            else:
                independ_list.append((x - l, x + l))

        if flag:
            cnt_ += 1

print(max(cnt, cnt_))

Submission status: Wrong Answer

Solution code:
N=int(input())
X=[[0,0]]*N
for i in range(N):
    X[i]=list(map(int,input().split()))
X.sort()
right=X[0][0]+X[0][1]
count=0
for i in range(1,N):
    if right>X[i][0]-X[i][1]:
        count+=1
    else:
        right=X[i][0]+X[i][1]
print(N-count)

Submission status: Wrong Answer

Solution code:
n = int(input())
machine = []
machine_left = []
machine_right = []
for i in range(n):
    x, l = [ int(v) for v in input().split() ]
    machine.append((x-l, x+l))
machine.sort(key = lambda x: x[1])

s = machine[0][1]
ans = 1
for l, r in machine[1:]:
    if l >= s:
        r = s
        ans += 1

print(ans)

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

ES = sorted(ES)
# print(ES)

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

Submission status: Wrong Answer

Solution code:

N = int(input())

robots = []

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

robots.sort()
new = []
for robot in robots:

    if len(new) == 0:
        new.append(robot)
    
    if (new[-1][0] + new[-1][1]) <= (robot[0] - robot[1]):
        new.append(robot)
        continue

print(len(new))

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)

    # dupl = [len([]) for i in range(N)]

    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:
        if i_min >= x_max:
            allowed.append(sorted_ranges[i])
            x_max = max(x_max, i_max)
            x_min = min(x_min, i_min)

    print(len(allowed))


def is_duplicates(range1, range2):
    return range1[1] > range2[0] or range1[0] < range2[1]


if __name__ == '__main__':
    main()

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][0]
cnt=1

print(list)

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())
p = []
for _ in range(N):
    x, n = [int(i) for i in input().split()]
    p.append((x-n, x+n))
p.sort()
i = 0
j = 1
c=0
while i<N and j<N:
    # print(p[i][0],p [j][0], p[i][1])
    if p[i][0]<=p[j][0]<p[i][1]:
        # print("!")
        j+=1
        c+=1
    else:
        i=j
        j+=1
v = N-c
p = p[::-1]
i = 0
j = 1
c=0
while i<N and j<N:
    # print(p[i][0],p [j][0], p[i][1])
    if p[i][0]<=p[j][1]<p[i][1]:
        # print("!")
        j+=1
        c+=1
    else:
        i=j
        j+=1
print(max(v, N-c))

Submission status: Wrong Answer

Solution code:
N = int(input())

X = []
d = {}

for _ in range(N):
    x,l = map(int, input().split())
    X.append(x)
    d[x] = l
X.sort()
count = 0
for i in range(1,len(X)):

    if i==(len(X)-1):
    
        I_left = (X[i]-d[X[i]]+1)
        K = (X[i-1]+d[X[i-1]]-1)
        if I_left<=K:
            count = count + 1
            i = i + 2
            if i>=N:
                break
            continue
        break

    I_right = (X[i]+d[X[i]]-1)
    I_left = (X[i]-d[X[i]]+1)

    J = (X[i+1]-d[X[i+1]]+1)
    K = (X[i-1]+d[X[i-1]]-1)
    if I_right>=J or I_left<=K:
        count = count + 1
        i = i + 2
        if i>=N:
            break
        continue
print(N-count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [list(map(int, input().split())) for _ in [0] * n]

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

c = 0
for i in range(10):
    i = 0
    while (i != len(s)-1 and i < len(s)):
        if s[i][1] >= abs(s[i][0] - s[i+1][0]):
            c += 1
            s.pop(i)
        i += 1


print(n-c)

Submission status: Wrong Answer

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

from operator import itemgetter
li=sorted(li, key=itemgetter(3))

ans=0
now=0

for i in range(n-1):
  if li[now][3]>=li[i+1][3]:
    ans+=1
    now+=1
  elif li[now][3]>li[i+1][2]:
    ans+=1
  else:
    now+=1

print(n-ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
L = []
for i in range(N):
  temp = list(map(int, input().split()))
  X.append(temp[0])
  L.append(temp[1])
  
area = []
num = 0
maxlength = max(X) + max(L)
for i in range(maxlength):
  area.append(0)
for i in range(N):
  if(L[i]==1):
    if(area[X[i]]==0):
      area[X[i]]=1
    else:
      num += 1
  for j in range(1,2*L[i]-1):
    if(X[i]-L[i]+j>=0):
      if(area[X[i]-L[i]+j]==0):
        area[X[i]-L[i]+j]=1
      else:
        num += 1
        break
print(N-num)

Submission status: Wrong Answer

Solution code:

n = int(input())


l = [list(map(int,input().split())) for i in range(n)]
l.sort()

count = 2
right = l[0][0]+l[0][1]
left = l[-1][0]-l[-1][1]
if right > left:
    print(1)
    exit()
for i in range(1,n):
    if l[i][0] == l[-i][0]:
        print(count)
        exit()
    if l[i][0]-l[i][1] >= right:
        count += 1
        right = l[i][0]+l[i][1]
    if l[i][0] == l[-i-1][0]:
        print(count)
        exit()   
    if left >= l[-i-1][0]+l[-i-1][1]:
        count += 1
        left = l[-i-1][0]-l[-i-1][1]
        
print(1)

Submission status: Wrong Answer

Solution code:
#N=int(input())
#N,M=map(int, input().split())
#L=list(map(int, input().split()))
N=int(input())
x=0
l=0
count=N
xL=[]
for _ in range(N):
  x,l=map(int, input().split())
  xL.append([x-l,x+l])
  
xL.sort()
for i in range(N-1):
  if xL[i][1]>xL[i+1][0]:
    if i<N-2:
      if xL[i+1][1]>xL[i+2][0]:
        xL[i+1]=[-9999999999999,-9999999999999]
      else:
        xL[i]=[-9999999999999,-9999999999999]
    else:
      xL[i]=[-9999999999999,-999999999999]
    count-=1
print(count)

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
m = len(xl)
while j < m:
    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
    m = len(xl)

print(len(xl))

Submission status: Wrong Answer

Solution code:

N = int(input())

XL = []
L = []
R = []

for i in range(N):

    x,l = map(int,input().split())
    L.append(x - l)
    R.append(x + l)

L.sort()
R.sort()
L.append(float("inf"))
R.append(float("inf"))

now = 0
flag = True
lind = 0
rind = 0
ans = 0
for i in range(2 * N):

    if L[lind] < R[rind]:
        now += 1
        flag = True
        lind += 1
    else:
        if flag:
            ans += 1
            flag = False
        now -= 1
        rind += 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
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
        #di.add(j)
    else:
        f-=1
        re+=f
print(n-re)

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[0]+x[1]))
m = -float("inf")
ans = 0
for n in range(N):
    if max(XL[n][0]-XL[n][1],-1)+1 >= m:
        ans += 1
        m = XL[n][0]+XL[n][1]
print(ans)

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]
ans = 1
for i in range(1, N):
    if robots[i][0] >= now:
        now = robots[i][1]
        ans += 1
print(ans)

Submission status: Wrong Answer

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

l.sort()

left=[]
right=[]
count=1

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