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:
from operator import itemgetter
N=int(input())
xl=[list(map(int, input().split())) for i in range(N)]
ab=[[xl[i][0]-xl[i][1], xl[i][0]+xl[i][1]] for i in range(N)]
ab=sorted(ab, key=itemgetter(0))
hiku=0
a=ab[0][0]
b=ab[0][1]
for i in range(1, N):
  if b>ab[i][0]:
    hiku+=1
  else:
    b=ab[i][1]
      
print(N-hiku)

Submission status: Wrong Answer

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

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

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

    if ans >= ans0:
        print(ans)
    else:
        print(ans0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

max_cnt = 0

not_accepted = []

for s in range(n):
    if max_cnt >= n - s + 1 or s not in not_accepted:
        break

    rxs2 = rxs_[s:]

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

    if max_cnt < cnt:
        max_cnt = cnt

print(max_cnt)

Submission status: Wrong Answer

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

for i in range(len(List)-2):
  migi = int(List[i][0] + List[i][1])
  hidari = int(List[i+2][0] - List[i+2][1])
  if migi > hidari:
    List[i][0] = -10000000000
    List[i][1] = 0
    cnt = cnt + 1
List.sort()
for i in range(len(List)-2):
  if i > 1:
    migi = int(List[i-2][0] + List[i-2][1])
    hidari = int(List[i][0] - List[i][1])
    if migi > hidari:
      List[i][0] = -10000000000
      List[i][1] = 0
      cnt = cnt + 1
List.sort()
for i in range(len(List)-1):
  if i > 0:
    hidari_1 = int(List[i][0] - List[i][1])
    migi_1 = int(List[i-1][0] + List[i-1][1])

    migi_2 = int(List[i][0] + List[i][1])
    hidari_2 = int(List[i+1][0] - List[i+1][1])
    
    if hidari_1 < migi_1 and migi_2 > hidari_2:
      List[i][0] = -10000000000
      List[i][1] = 0
      cnt = cnt + 1
List.sort()
for i in range(len(List)-1):
  hidari = int(List[i+1][0] - List[i+1][1])
  migi = int(List[i][0] + List[i][1])
  if hidari < migi:
    List[i][0] = -10000000000
    List[i][1] = 0
    cnt = cnt + 1

print(N-cnt)

Submission status: Wrong Answer

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

K = len(lis)

X = 0
N = 0
co = 0
ans = 0


for i in range(len(lis)):
    h = []
    h = lis[i]
    X = h[0]
    N = h[1]
    if i == 0:
        co = X+N
    else:
        if co - X <= 0:
            co = X+N
        else:
            co = X+N
            K -= 1
print(K)

Submission status: Wrong Answer

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

i, j = 0, 1
count = N
while i < count - 1:
  if XL[i][0] + XL[i][1] > XL[j][0] - XL[j][1]:
    if XL[i][0] + XL[i][1] < XL[j][0] + XL[j][1]:
      j += 1
    else:
      i, j = j, j + 1
    count -= 1
  else:
    i, j = j, j + 1
print(count)

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-2):
            if(robots_sorted[n-2]['l'] * 2 >= robots_sorted[n-1]['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):
    x, l = map(int, input().split())
    robots.append((x, l))

robots = sorted(robots, key=lambda x: x[0])
rightest_point = robots[0][0] + robots[0][1] - 1
ans = 0
# 無理やり一体目を置いた時
for i in range(1, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
first = N-ans
if N == 1:
    print(1)
    exit()
# 1体目を置かない場合
rightest_point = robots[1][0] + robots[1][1] - 1
ans = 1  # 一体目を置かないので
for i in range(2, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
second = N-ans
print(max(first, second))

Submission status: Wrong Answer

Solution code:
N = int(input())

robot = [[0 for i in range(3)] for j in range(N)]

for k in range(N):
    x, l = [int(l) for l in input().split()]
    robot[k][0] = x
    robot[k][1] = x - l
    robot[k][2] = x + l

robot = sorted(robot)

#print(robot)

count = 0

for m in range(N-1):
    try:
        if ((robot[m+1][2] > robot[m+2][1]) or (robot[m][2] > robot[m+1][1])):
            del robot[m+1]
            N = N-1
        else:
            continue
    except:
        break

print(len(robot))

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<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<nx+nl: continue
    ans2 += 1
    x, l = nx, nl
print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = int(input())
    xl = []
    for i in range(n):
        a,b = map(int,input().split())
        xl.append([a,b])
    xl.sort()
    ans = 1
    width = xl[0]
    count = 0
    for i in range(1,n):
        if max(xl[i][0] - xl[i][1] + 1,0) < width[0] + width[1] - 1:
            count += 1
            if count == 2:
                width = xl[i]
                ans += count
                count = 0
        else:
            ans += 1
            count = 0
            width = xl[i]
    print(ans)
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

point_num = int(input())
robot_list = [list(map(int, input().split())) for i in range(point_num)]
robot_list = sorted(robot_list, key=lambda x:x[0])

counter = 0
for _ in range(point_num-1):
  counter += 1
  if robot_list[counter-1][0] + robot_list[counter-1][1] > robot_list[counter][0] - robot_list[counter][1]:
    del robot_list[counter]
    counter -= 1

print(len(robot_list))

Submission status: Wrong Answer

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

num=0
for i in range(n):
    try:
      if int(a[i][0])<int(a[1+1][0]):
        if int(a[i][0])+int(a[i][1])>int(a[i+1][0])-int(a[i+1][1]):
              a.pop(i+1)
              num+=1
      if int(a[i][0])>int(a[i+1][0]):
        if int(a[i+1][0])+int(a[i+1][1])>int(a[i][0])-int(a[i][1]):
              a.pop(i+1)
              num+=1

    except IndexError:
        print(n-num)
        exit()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ll=[]
for i in range(n):
  x,l=map(int,input().split())
  ll.append([x,l])
ll.sort()  
renzoku=[]
cnt=0
for i in range(n-1):
  if ll[i][0]+ll[i][1]-1 >= ll[i+1][0]-ll[i+1][1]+1:
    cnt+=1
    if i==n-2:
      renzoku.append(cnt)
  else:
    renzoku.append(cnt)
    cnt=0
cnt2=0
for i in renzoku:
  if i==2 or i==1:
    cnt2+=1
  elif i>2:
    cnt2+=int(math.ceil(i/2))
print(n-cnt2)

Submission status: Wrong Answer

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

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

lr = sorted(lr)
remove = [0] * n

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

remove = sum(1 for x in range(n) if remove[x] == 1)
print(n - remove)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import bisect
N=int(input())
d=[0]*N
s=[0]*N
for i in range(N):
    a,b=map(int,input().split())
    s[i]=a-b
    d[i]=a+b
d.sort()
s.sort()
cnt=[]
#print(d)
#print(s)
for i in range(N):
    cnt.append(N-bisect.bisect_left(s,d[i]))
    #print(cnt)
#print(cnt[0]+1)
tmp=0
for i in range(N-1):
    if cnt[i]==cnt[i+1]:
        tmp+=1
print(N-tmp)

Submission status: Wrong Answer

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

N = int(input())
X = []

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

X.sort()
flag = []
cnt = 0
for i, t in enumerate(X):
    if i == 0:
        flag.append(1)
        continue
    if (X[cnt][0]+X[cnt][1] > t[0]-t[1]):
        flag.append(0)
    else:
        flag.append(1)
        cnt = i

print(sum(flag))

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])
rightest_point = robots[0][0] + robots[0][1] - 1
ans = 0
# 無理やり一体目を置いた時
for i in range(1, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
first = N-ans
if N == 1:
    print(first)
    exit()
# 1体目を置かない場合
rightest_point = robots[1][0] + robots[1][1] - 1
ans = 1  # 一体目を置かないので
for i in range(2, len(robots)):
    if robots[i][0]-robots[i][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[i][0]+robots[i][1] - 1
second = N-ans
print(max(first, second))

Submission status: Wrong Answer

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

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

prek = l[0][0]
prea = l[0][1]
cnt = N

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

Submission status: Wrong Answer

Solution code:
robot_num = int(input())
robots = []
delete_robot = 0

for i in range(0,robot_num):
  robots.append(input().split(" "))
    
"""ここで、座標の小さい順番にソートする。"""
for i in range(0, robot_num):
  for j in range(1, robot_num):
    if int(robots[i][0]) > int(robots[j][0]):
      tmp = robots[i]
      robots[i] = robots[j]
      robots[j] = tmp
            
"""座標の差と、腕の長さの和を計算して、大小比較を行う。"""
for i in range(0, robot_num-1):
  delta_X =  int(robots[i][0]) - int(robots[i+1][0])
  arm_length_sum = int(robots[i][1]) + int(robots[i+1][1])
  if arm_length_sum > delta_X:  # ここでは、ぶつかってしまう時を考えている。
    delete_robot += 1
  """ここまででは、もしかしたら余分にロボットを消してしまう可能性がある。"""

if robot_num % 2 == 1:
  print(int(robot_num - delete_robot/2 + 1))
else:
  print(int(robot_num - delete_robot/2))

Submission status: Wrong Answer

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

#output
import bisect as bi
X.sort()
Y = []
Y.append(X[0])

sum = 1
worm = X[0] + L[0]
while worm <= X[-1]:
    worm = bi.bisect_left(X, worm)
    worm = X[worm] + 2*L[i]
    sum += 1

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
robolist =[[]]*N
for i in range(N):
  robolist[i] = list(map(int, input().split()))
robolist.sort()
nrobo = 1
xmax = robolist[0][0] + robolist[0][1]
for j in range(1,N):
  if xmax <= robolist[j][0] - robolist[j][1]:
    nrobo += 1
    xmax = robolist[j][0] + robolist[j][1]
print(nrobo)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	tmp = []
	for i in range(N):
		X,L = inputMap()
		LL = X-L
		RR = X+L
		tmp.append((LL,RR))

	tmp.sort()
	kabu = 0
	tt = []
	for i,val in enumerate(tmp):
		if i == len(tmp)-1:
			break

		ima_L,ima_R = val
		tugi_L, tugi_R = tmp[i+1]

		if ima_R > tugi_L:
			kabu += 1

		tt.append(kabu)
		kabu = 0

	kk = 0
	cari = 0
	for i,val in enumerate(tt):
		if i == len(tmp)-2:
			break

		ptn = (tt[i],tt[i+1])

		if ptn == (1,0):
			if cari == 0:
				kk += 1
			else:
				cari = 0

		elif ptn == (1,1):
			if cari == 0:
				kk += 1
				cari = 1
			else:
				cari = 0

	print(N-kk)


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [tuple(map(int, input().split())) for i in range(N)]

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

t = list(map(lambda j:(j[0]-j[1]+1, j[0]+j[1]-1), s))
NN = len(t)

for k in range(NN):
  for l in range(k+1, NN):
    if int(t[k][1]) <= int(t[l][1]):
      if (t[l][0] <= t[k][1]) and (t[k][1] <= t[l][1]):
        N -= 1
        break
    else:
      if (t[l][0] <= t[k][0]) and (t[k][0] <= t[l][1]):
        N -= 1
        break
        
print(N)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
ll = []
rr = []
for _ in range(N):
    x1, l1 = map(int, input().split())
    ll.append(x1-l1)
    rr.append(x1+l1)
    
a = np.argsort(ll)

l = [0] * N
r = [0] * N
for i in range(N):
    l[i] = ll[a[i]]
    r[i] = rr[a[i]]
    
ans = N
con = 0
for i in range(N):
    cnt = 0
    if con == 1:
        con = 0
        continue
    for j in range(i+1,N):
        if r[i] > l[j]:
            cnt += 1
        else:
            if cnt == 1:
                con = 1
                ans -= 1
                break
            else:
                break
        if cnt == 2:
            ans -= 1
            break
        if cnt == 1 and j == N-1:
            ans -= 1
            break
            
print(ans)

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])
flag = 1
ans1 = ans2 = 1
x, l = xls[0]
for i in range(1, n):
    nx, nl = xls[i]
    if nx-nl<x+l: continue
    if i==1: flag=0
    ans1 += 1
    x, l = nx, nl

if flag and len(xls)>1:
    x, l = xls[1]
    for i in range(2, n):
        nx, nl = xls[i]
        if nx-nl<x+l: continue
        if i==1: flag=0
        ans2 += 1
        x, l = nx, nl
print(max(ans1, ans2))

Submission status: Wrong Answer

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

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

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)

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:
N = int(input())
XList = []
LList = []

for i in range(0, N):
    X, L = map(int, input().split())
    XList.append(X)
    LList.append(L)

TMP = zip(XList, LList)
tmp = sorted(TMP)
XList, LList = zip(*tmp)
XList = list(XList)
LList = list(LList)

for i in range(0, N):
    if i >= N - 1:
        break
    elif i == 0:
        if XList[i] + LList[i] > XList[i + 1] - LList[i + 1]:
            XList.pop(i + 1)
            LList.pop(i + 1)
            i -= 1
            N -= 1
    elif XList[i - 1] + LList[i - 1] > XList[i] - LList[i] or XList[i] + LList[i] > XList[i + 1] - LList[i + 1]:
        XList.pop(i + 1)
        LList.pop(i + 1)
        i -= 1
        N -= 1
print(N)

Submission status: Wrong Answer

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

removal_count = 0
for index, arm in enumerate(s):
  if arm[0]+arm[1]>= s[index][0]+s[index][1]:
    removal_count += 1
print(N-removal_count)

Submission status: Wrong Answer

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

cnt1, cnt2, cnt3, cnt4 = 0, 0, 0, 0
max_n1,max_n2,max_n3,max_n4 = sum(a1[0]),sum(a2[0]),sum(a3[0]),sum(a4[0])

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

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

for point, area in a3[1:]:
    i = point-area
    if max_n3 > i:
        cnt3 += 1
    else:
        max_n3 = point+area

for point, area in a4[1:]:
    i = point-area
    if max_n4 > i:
        cnt4 += 1
    else:
        max_n4 = point+area

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

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

    XL.sort()

    res1 = 1
    right = sum(XL[0])

    for i in range(1,N):
        if right <= XL[i][0] - XL[i][1]:
            res1 += 1
            right = sum(XL[i])

    res2 = 1
    left = sum(XL[N-1])

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

    res = max(res1,res2)


    print(res)



main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

count = n

xl.sort(key=lambda x: x[0])
d = {}
for i in range(len(xl)):
    try:
        d[i] = 0
        if i > 0:
            if xl[i][0] - xl[i][1] < xl[i - 1][0] + xl[i - 1][1]:
                d[i] += 1
        if i < len(xl) - 1:
            if xl[i][0] + xl[i][1] > xl[i + 1][0] - xl[i + 1][1]:
                d[i] += 1

        if d[i] > 1:
            d.pop(i)
            xl.pop(i)
            n -= 1
            count -= 1
    except IndexError:
        continue


for i in range(len(xl)):
    try:
        d[i] = 0
        if i > 0:
            if xl[i][0] - xl[i][1] < xl[i - 1][0] + xl[i - 1][1]:
                d[i] += 1
        if i < len(xl) - 1:
            if xl[i][0] + xl[i][1] > xl[i + 1][0] - xl[i + 1][1]:
                d[i] += 1

        if d[i] > 0:
            d.pop(i)
            xl.pop(i)
            n -= 1
            count -= 1
    except IndexError:
        continue


print(count)

Submission status: Wrong Answer

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

N = int(input())
X = []

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

X.sort()
flag = []
cnt = 0
for i, t in enumerate(X):
    if i == 0:
        flag.append(1)
    if (X[cnt][0]+X[cnt][1] > t[0]-t[1]):
        flag.append(0)
    else:
        flag.append(1)
        cnt = i

print(sum(flag))

Submission status: Wrong Answer

Solution code:
n = int(input().rstrip())
robos = []
max = 0

count = 0
item_list = []

for i in range(n):
    line = input().rstrip().split(' ')
    item = [int(line[0]), int(line[1])]
    countFlg = False
    for a in item_list:
        if item[0] + item[1] - 1 < a[0] - a[1] + 1 or item[0] - item[1] + 1 > a[0] + a[1] - 1:
            countFlg = True
            break
        elif not(a[0] - a[1] + 1 < item[0] - item[1] + 1 or item[0] + item[1] - 1 < a[0] + a[1] - 1):
            countFlg = True
            break
        
    if len(item_list) < 1:
        countFlg = True

    if countFlg == True:
        count += 1
        item_list.append(item)

print(count)

Submission status: Wrong Answer

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

N = len(lis)

X = 0
N = 0
co = 0
ans = 0


for i in range(len(lis)):
    h = []
    h = lis[i]
    X = h[0]
    N = h[1]
    if i == 0:
        co = X+N
        N -= 1
    else:
        if co - X <= 0:
            co = X+N
            N -= 1
        else:
            co = X+N

print(N)

Submission status: Wrong Answer

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

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
xlis=sorted([list(map(int,input().split())) for i in range(n)])
counter=0
nlis=[]
rlis=[]
highest=-1000000000000
th=0
for i in range(n):
    high=xlis[i][0]+xlis[i][1]
    low=xlis[i][0]-xlis[i][1]
    nlis.append([low,high])
    rlis.append([low,high])
for i in range(n-2):
    if nlis[i][1]>nlis[i+2][0]:
        rlis.remove(nlis[i])
print(rlis)
for i in range(len(rlis)):
    if rlis[i][0]>=highest:
        counter+=1
        highest=rlis[i][1]
        th=0
print(counter)

Submission status: Wrong Answer

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

d = []

for xl in X_L:
  d.append([xl[0] - xl[1], 1])
  d.append([xl[0] + xl[1] - 1, -1])

d.sort(key=lambda x: x[0])
#print(d)
max_ = 0
tmp = 0
for d in d:
  tmp += d[1]
  max_ = max(tmp, max_)
print(N - max_ + 1)

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] - 1 ##right
    left = xl[i][0] - xl[i][1] + 1 ##left   
    itv.append([right,left])
itv.sort()

ass = 0
tt = int(-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:
N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
P.sort()

c = 0
x = 1
for i in P:
  a = i[0] - i[1]
  b = i[0] + i[1]
  if a>=c:
    x += 1
    c = b
  else:
    pass

if x >= N:
  x = N
print(x)

Submission status: Wrong Answer

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

    
robots = sorted(robots, key=lambda x:x[1])
covered_x = robots.pop(0)[1]
robots_num = 1
try:
    while True:
        robots = filter(lambda r: r[0] > covered_x, robots)
        covered_x = next(robots)[1]
        robots_num += 1
except StopIteration:
    pass
print(robots_num)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
def sortOd(val):return val[0]
N = int(stdin.readline())
A = [list(map(int,stdin.readline().split())) for i in range(N)]
A.sort(key=sortOd)
i = 0
while i < len(A)-1:
	if A[i][1]+A[i+1][1] > A[i+1][0]-A[i][0]:A.pop(i) if A[i][1] <= A[i+1][1] else A.pop(i+1)
	i += 1
print(len(A))

Submission status: Wrong Answer

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

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

lr = sorted(lr)
remove = 0

if n > 2:
    for i in range(1, n - 1):
        if lr[i - 1][0] == lr[i][0]:
            remove += 1
        elif lr[i - 1][0] < lr[i][0] < lr[i - 1][1]:
            if not lr[i][0] < lr[i + 1][0] < lr[i][1]:
                remove += 1
elif n == 2:
    if lr[0][0] == lr[0][0]:
        remove += 1
    elif lr[0][0] < lr[1][0] < lr[0][1]:
        remove += 1
elif n == 1:
    pass

print(n - remove)

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

    XL.sort()

    res1 = 1
    right = sum(XL[0])

    for i in range(1,N):
        if right <= XL[i][0] - XL[i][1]:
            res1 += 1
            right = sum(XL[i])

    res2 = 1
    left = sum(XL[N-1])

    for i in range(N-2,-1,-1):
        if left <= XL[i][0] + XL[i][1]:
            res2 += 1
            left = XL[i][0] - XL[i][1]

    res = max(res1,res2)


    print(res)



main()

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [tuple(map(int, input().split())) for i in range(N)]

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

t = list(map(lambda j:(j[0]-j[1]+1, j[0]+j[1]-1), s))

for k in range(len(t)):
  for l in range(k+1, len(t)):
    if int(t[k][1]) < int(t[l][1]):
      if (t[l][0] < t[k][1]) and (t[k][1] < t[l][1]):
        N -= 1
        break
    else:
      if (t[l][0] < t[k][0]) and (t[k][0] < t[l][1]):
        N -= 1
        break
        
print(N)

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, j = 0, 1
while i < N:
    if j < N and sum(XL[i]) > XL[j][0] - XL[j][1]:
        if sum(XL[i]) < sum(XL[j]):
            res += 1
            while j < N and sum(XL[i]) > XL[j][0] - XL[j][1]:
                j += 1
            i, j = j, j + 1
        else:
            i += 1
            j += 1
    else:
        res += 1
        i += 1
        j += 1

print(res)