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: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input)
#h,w = [int(i) for i in readline().split()]
#n,*w = [int(i) for i in read().split()]

n = int(input())

res = []
for i in range(n):
    x,l = [int(i) for i in readline().split()]
    res.append((x-l,x+l))

from operator import itemgetter
res.sort(key=itemgetter(1))

#print(res)

ans = 0
now = res[0][0] - 10
for l,r in res:
    if now <= l:
        ans += 1
        now = r
    

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
XL=[]
for i in range(n):
  x,l=map(int,input().split())
  XL.append([x-l,x,x+l])
ans=0
cur=-float("inf")
XL.sort(key=lambda x:x[2])
for x1,x2,x3 in XL:
  if x1>=cur:
    cur=x3
    ans+=1
  else:
    continue
print(ans)

Submission status: Accepted

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

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

for i in range(n):
    A.append([L[i][0]-L[i][1], L[i][0]+L[i][1]])
A.sort(key=lambda x:x[1])

m = -float("inf")
ans = 0
for i in range(n):
    if m > A[i][0]:
        ans += 1
    else:
        m = A[i][1]
print(n-ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
XL = [LIST() for _ in range(N)]

range_lis = [(x[0]-x[1], x[0]+x[1]) for x in XL]
# print(range_lis)

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

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

Submission status: Accepted

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

ls2 = list()

for i in range(n):
    ls2.append([ls[i][0]-ls[i][1], ls[i][0]+ls[i][1]])

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

idx=ls2[0][0]
ans=0

for i in range(n):
    if idx<=ls2[i][0]:
        idx=ls2[i][1]
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
robots = []
for i in range(n):
    x, l = [int(item) for item in input().split()]
    robots.append((x+l, x-l))

robots.sort()

cnt = 0
node = -10**12
for end, start in robots:
    if start >= node:
        node = end
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def examA():
    H = I()
    W = I()
    N = I()
    ans = (N-1)//max(H,W) + 1
    print(ans)
    return

def examB():
    N = I()
    XL = [LI()for _ in range(N)]
    for i in range(N):
        XL[i][0] += XL[i][1]
    XL.sort()
#    print(XL)
    ans = 0
    now = -inf
    for i in range(N):
        if XL[i][0]-XL[i][1]*2>=now:
            ans +=1
            now = XL[i][0]
    print(ans)
    return

def examC():
    return

def examD():
    return

def examE():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

Submission status: Accepted

Solution code:
N = int(input())

X = []

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

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

count = 0
prev = -10**27
for i in range(N):
    if prev<=X[i][0]:
        prev = X[i][1]
        count+=1

print(count)

Submission status: Accepted

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

arm.sort(key = lambda x: x[1])
ans = 0
now = -10**10
for i in range(n):
    if now <= arm[i][0]:
        ans += 1
        now = arm[i][1]

print(ans)

Submission status: Accepted

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

xl.sort(key=lambda x: x[0] + x[1])
ans = 0
i = 0
j = -10**9*2
while i < n:
    t = xl[i]
    if j <= t[0] - t[1]:
        ans += 1
        j = t[0] + t[1]
    i += 1
print(ans)

Submission status: Accepted

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

N = int(input())

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

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

count = 0
tmp = - 10 ** 18
for i in lst:
    if tmp <= i[0]:
        count += 1
        tmp = i[1]

print (count)

Submission status: Accepted

Solution code:
n = int(input())
li = [None] * n
for i in range(n):
    x, l = map(int, input().split())
    li[i] = (x - l, x + l)
li.sort(key=lambda x: x[1])
f = -float('inf')
ans = 0
for p, q in li:
    if p >= f:
        ans += 1
        f = q
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter


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

li = []
for i in range(n):
    x, l = info[i]
    li.append((x - l, x + l))
li = sorted(li, key = itemgetter(1))

r_max = - 10**18
ans = 0
for i in range(n):
    l, r = li[i]
    if r_max <= l:
        ans += 1
        r_max = r
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
a = - (1 << 100)
X = []
for _ in range(N):
    x, l = map(int, input().split())
    X.append((x, l))
X = sorted(X)
for x, l in X:
    if a > x - l:
        a = min(a, x + l)
    else:
        a = x + l
        ans += 1
print(ans)

Submission status: Accepted

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

R = [(X - L, X + L) for X, L in XL]
R.sort(key=lambda x: x[1])

ret = 0
rmax = -float('inf')
for l, r in R :
  if l >= rmax :
    ret += 1
    rmax = r
    
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
arms = [list(map(int, input().split())) for _ in range(n)]
arms.sort(key=lambda x: x[0]+x[1])
ans = 0
cur = -10**20
for x, l in arms:
	if x-l >= cur:
		ans += 1
		cur = x+l
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]+x[1])
c=-float("INF")
an=0
for i,j in d:
    if i-j>=c:
        an+=1
        c=i+j
print(an)

Submission status: Accepted

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

robots = [(x+l,x-l) for x,l in robots]

robots.sort()

cnt = 0
last = -float('inf')
for r,l in robots:
    if last <= l:
        cnt += 1
        last = r

print(cnt)

Submission status: Runtime Error

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    ranges = []
    for i in range(n):
        x, l = LI()
        ranges.append([x - l, x + l])
    ranges.sort(key=lambda x: x[0])
    ans = n
    for i in range(1, n):
        if ranges[i - 1][1] > ranges[i][0]:
            ans -= 1
            if range[i - 1][1] - range[i - 1][0] > range[i][1] - range[i][0]:
                ranges[i][1] = -INF
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    ranges = []
    for i in range(n):
        x, l = LI()
        ranges.append((x - l + 1, x + l - 1))
    ranges.sort(key=lambda x: x[0])
    ans = n
    for i in range(1, n):
        if ranges[i - 1][1] >= ranges[i][0]:
            ans -= 1
            ranges[i][1] = -INF
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    ranges = []
    for i in range(n):
        x, l = LI()
        ranges.append((x - l + 1, x + l - 1))
    ranges.sort(key=lambda x: x[0])
    ans = n
    for i in range(1, n):
        if ranges[i - 1][1] >= ranges[i][0]:
            ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
se = [()] * N
for i in range(N):
	x, l = map(int, input().split())
	se[i] = (x-l, x+l)
se = sorted(se, key=lambda x: x[1])
ans = N
for i in range(1, N):
	if se[i-1][1] > se[i][0]:
		se[i][1] = se[i-1][1]
		ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
INF=10**20

X=[]
for i in range(N):
  x,l=map(int,input().split())
  X.append((x-l,x+l-1))
  
X = sorted(X)
rmax=-INF
res=[]
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
for i in range(len(res)):
  if res[i]==2:
    dellist.append(i)

for i in range(len(dellist)):
  del X[dellist[i]]
  
rmax=-INF
res=[]
N=len(X)
for i in range(N):
  cnt=0
  if rmax>=X[i][0]:
    cnt+=1
  if i<N-1 and X[i][1]>=X[i+1][0]:
    cnt+=1
  res.append(cnt)
  rmax = max(rmax,X[i][1])
  
dellist=[]
flag=0
for i in range(len(res)-1):
  if flag==0 and res[i]==res[i+1]==1:
    dellist.append(i)
    flag=1
  if flag:
    flag=0

for i in range(len(dellist)):
  del X[dellist[i]]
  
print(len(X))

Submission status: Runtime Error

Solution code:
import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    XL = [NLI() for _ in range(N)]
    

    arm_range = []
    for n in range(N):
        arm_len = XL[1]
        arm_range.append([XL[n][0]-XL[n][1],XL[n][0]+XL[n][1]])

    
    sorted_arm_range = sorted(arm_range, key=lambda x: x[1])  #[1]に注目してソート

    
    x = 0
    ans = 1
    while x<N-1:
        arm_end = sorted_arm_range[x][1]
        while x<N-1 and sorted_arm_range[x+1][0] < arm_end:
            x += 1
        ans += 1
        x += 1
        
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
imo = []
xlmin = 0
xlmax = 0
for _ in range(N):
    x,l = map(int,input().split())
    imo.append([x-l,x+l])
    xlmin = min(xlmin,x-l)
    xlmax = max(xlmax,x+l)

point = [0]*(xlmax-xlmin+2)

for i in range(N):
    point[imo[i][0]-xlmin+1] += 1
    point[imo[i][1]-xlmin+1] -= 1

now = 0
cnt = 0
befor = 0
for i in range(len(point)):
    before = now
    now += point[i]
    if point[i]>=1 and now >1:
        cnt += now-before

print(N-cnt)

Submission status: Runtime Error

Solution code:
from collections import deque
n = int(input())
cou = n
l_h = []
for i in range(n):
  x,l  = map(int,input().split())
  l_h.append([x-l,x+l])
l_h.sort(key=lambda x: x[1])
d = deque(l_h)
t= d.popleft()
a,b = t[0],t[1]
for i in range(n-1):
  m= d.popleft()
  c,e= m[0],m[1]
  if b<=c:
    b = d
  else:
    cou -= 1
print(cou)

Submission status: Runtime Error

Solution code:
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0])
i = 1
while 1:
    if data[i][0] - data[i][1] < data[i - 1][0] + data[i - 1][1]:
        del data[i]
    else:
        i += 1
    if i >= len(data) - 1:
        break
print(len(data))

Submission status: Runtime Error

Solution code:
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0])
i = 0
while 1:
    if data[i][0] + data[i][1] > data[i + 1][0] - data[i + 1][1]:
        del data[i + 1]
    else:
        i += 1
    if i >= len(data) - 1:
        break
print(len(data))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

diff = [0] * N
neg = []
pos = []
for i in range(N):
    diff[i] = A[i] - B[i]
    if diff[i] < 0:
        neg.append(diff[i])
    else:
        pos.append(diff[i])

if sum(diff) < 0:
    print(-1)
    exit(0)

tobe_supplied = sum(neg)
pos.sort(reverse=True)

cnt = len(neg)

for p in pos:
    if tobe_supplied >= 0:
        break
    cnt += 1
    tobe_supplied += p    

print(cnt)

Submission status: Runtime Error

Solution code:
    p = sorted([(a+b, a-b) for a, b in zip(x, l)])
    _, th = p[0]
    best = 0
    for t, s in p:
        if th <= s:
            best += 1
            th = t
    return best

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
for i in range(n):
  x,l=map(int,input().split())
  a.append(list(range(x-l+1,x+l)))
ans=[]
while(len(a)):
  b=[]
  for i in a:
    b.append(i[-1])
  bi=b.index(min(b))
  bm=b.pop(bi)
  am=a.pop(bi)
  ans.append(am)
  for i in a:
    if bm in i:
      a.remove(i)
      
print(len(ans))

Submission status: Runtime Error

Solution code:
def test(array, index, last_position, count, min_count):
    if index + 1 == len(array):
        # print("count:{}".format(count))
        min_count[0] = count if min_count[0] == - \
            1 or count < min_count[0] else min_count[0]
        return
    current = array[index]
    next = array[index + 1]

    # 前か次のと手がぶつかる場合は取り除く
    if last_position >= current[0] - \
            current[1] or current[0] + current[1] >= next[0] - next[1]:
        test(array, index + 1, last_position, count + 1, min_count)
    # 前のとぶつからない場合は取り除かないパターンも
    if last_position < current[0] - current[1]:
        test(array, index + 1, index, count, min_count)


N = int(input())
array = sorted([list(map(int, input().split()))
                for i in range(N)], key=lambda x: x[0])
min_count = [-1]
test(array, 0, -1, 0, min_count)
print(len(array) - min_count[0])

Submission status: Runtime Error

Solution code:
import sys

n = int(input())
robots = [sys.stdin.readline() for _ in range(n)]
robots = sorted(robots, key=lambda x:x[0])
del_count = 0
del_locs = []

for i, robot_loc in enumerate(robots):
    if robot_loc in del_locs:
        continue
    for j in range(len(robots)-i):
        if robots[i+j] in del_locs:
            continue
        center_dis = robots[i+j][0] - robot_loc[0]
        distance = robots[i+j][1] + robot_loc[1]
        if distance >= center_dis: # 重なる時
            if robot_loc[1] >= robots[i+j][1]:
                del_locs.append(robot_loc)
                del_count += 1
                break
            else:
                del_locs.append(robots[i+j])
                del_count += 1

print(n - del_count)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N = int(input())
l = [list(map(int, input().split())) for _ in range(N)]
ans = []
for i in range(N):
  l[i].append(l[i][0] - l[i][1])
  l[i].append(l[i][0] + l[i][1])
  del l[i][:2]
l.sort(key = itemgetter(1))

def search(x):
  for i in range(x, len(l)):
    if l[i][0] < l[i-1][1]:
      del(l[i])
      ans.append(1)
      search(x)
      break
search(1)
if ans == []:
  print(N)
else:
  print(N-sum(ans))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

N = int(input())
XL = [list(map(int, input().split())) for n in range(N)]
m = max(XL, key=lambda x: x[0])
line = np.array([False]*(m[0]+m[1]))
ans = 0

XL.sort(key=lambda x: x[0]+x[1])
for xl in XL:
  xmax = xl[0] + xl[1]
  xmin = xl[0] - xl[1] if xl[0]-xl[1] > 0 else 0
  if not(any(line[xmin:xmax])):
    line[xmin:xmax] = [True]
    ans +=1

print(ans)

Submission status: Runtime Error

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

N = int(input())
XL = [list(map(int, input().split())) for n in range(N)]
m = max(XL, key=lambda x: x[0])
line = [False]*(m[0]+m[1])
ans = 0

XL.sort(key=lambda x: x[1])
for xl in XL:
  x = xl[0]
  l = xl[1]
  if not(all(line[x-l:x+l])):
    line[x-l:x+l] = [True]*(2*l)
    ans +=1


print(ans)

Submission status: Runtime Error

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

N = int(input())
XL = [list(map(int, input().split())) for n in range(N)]
m = max(XL, key=lambda x: x[0])
line = [False]*m[0]
ans = N

XL.sort(key=lambda x: x[1])
for xl in XL:
  x = xl[0]
  l = xl[1]
  if all(line[x-l:x+l]):
    ans -=1
  else:
    line[x-l:x+l] = [True]*(2*l)


print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(n)]
R=[list(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(n-1):
    if r[i+1][0]>=s:
        s=r[i+1][1]
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(N)]
R=[list(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(n-1):
    if r[i+1][0]>=s:
        s=r[i+1][1]
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(N)]
R=[list(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(n-1):
    if r[i+1][0]>s:
        s=r[i+1][1]
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(N)]
R=[list(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(1,n):
    if r[i][0]>s:
        s=r[i][1]
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
 
lines = []
for i in range(n):
  x,l = map(int,input().split())
  lines.append([x-l,x+l])
lines = sorted(lines)
count = 0
kari = -9999999999999
for i in range(n):
  if lines[i][0] >= kari:
    count += 1
    kari = lines[i][1]
print(count)
n = int(input())

lines = []
for i in range(n):
  x,l = map(int,input().split())
  lines.append([x-l,x+l])
lines = sorted(lines,key = lambda x:x[1])
count = 0
kari = -9999999999999
for i in range(n):
  if lines[i][0] >= kari:
    count += 1
    kari = lines[i][1]
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append(x+l)
    t = 0
    for i in range(n):
        if t < hoge[i]:
            ans += 1
            t = hoge[i]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    x, l = [0]*n, [0]*n
    for i in range(n):
        x[i], l[i] = map(int, input().split())
    hoge = []
    for i in range(n):
        hoge.append(x+l)
    t = 0
    for i in range(n):
        if t < hoge[i]:
            ans += 1
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
nums = [list(map(int, input().split())) for _ in range(N)]
for row in nums:
  row.append(row[0]+row[1])
  row.append(row[0]-row[1])

nums.sort(key=lambda x: x[2])
ans_1 = N
ans_2 = N

point_1 = nums[0][2]
point_2 = nums[1][2]
for j in range(N-1):
  if nums[j+1][3] < point_1:
    ans_1 -= 1
  else:
    point = nums[j][2]
for j in range(N-1):
  if nums[j+1][3] < point_2:
    ans_2 -= 1
  else:
    point = nums[j][2]
print(max(ans_1, ans_2))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""
N = int(input())
xl = [list(map(int, input())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -10000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""


N = int(input())
xl = [list(map(int, input())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -10000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 07:49:36 2020

@author: naoki
"""

f = open("C:/Users/naoki/Desktop/Atcoder/input.txt")

N = int(input())
xl = [list(map(int, input())) for _ in range(N)]

left_right = [[row[0]-row[1], row[0]+row[1]] for row in xl]
left_right = sorted(left_right, key = lambda x:int(x[1]))
count = 0
now = -10000
for row in (left_right):
    if row[0] < now:
        continue
    else:
        count += 1
        now = row[1]

Submission status: Runtime Error

Solution code:
n = int(input())
xl = [list(map(int, input().split())) for _ in range(n)]
le = [[p[0]-p[1], p[0]+p[1]] for p in xl]
le.sort(key = lambda x　: x[1])

ans = 0
right = -(10 ** 9) -　1
for i in range(n):
    if right <= le[i][0]:
        ans += 1
        right = le[i][1]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
ts = []
for _ in range(N):
    x, l = map(int,input().split())
    t = min(x+l,10**9)
    s = max(x-l,0)
    ts.appned([t,s])

ts.sort()

tmp = 0
count = 0
for n in ts:
    if tmp<=n[1]:
        count += 1
        tmp = n[0]

print(count)

Submission status: Runtime Error

Solution code:
def solve(N, XL):
    XL_re = [[xl[0] - xl[1], xl[0] + xl[1]] for xl in XL]
    XL_re = sorted(XL_re, key=lambda x: x[1])

    cnt = 0
    for i, xl in enumerate(XL_re):
        if i == 0:
            tmp = xl[1]
            cnt += 1
        else:
            if tmp <= xl[0]:
                tmp = xl[1]
                cnt += 1
    return cnt

def test():
    assert solve(4, [[2, 4], [4, 3], [9, 3], [100, 5]]) == 3

def main():
    N = int(input())
    XL = [list(map(int, input().split())) for _ in range(N)]
    ans = main(N, XL)
    print(ans)

if __name__ == "__main__":
    # test()
    main()

Submission status: Runtime Error

Solution code:
from collections import deque

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

p = deque()

for i in list:
  p.append([i[0] - i[1],i[0] + i[1]])
  
p = sorted(p,key = lambda x: x[1])

ex = []
ex.append(p.pop(left))




for i in range(len(p)):
  if(ex[-1][1] <= p[0][0]):
    ex.append(p.pop(left))
  else:
    p.pop(left)

print(len(ex))

Submission status: Runtime Error

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

from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

def myinput():
    return map(int,readline().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    return data.sort(key=lambda x:x[col],reverse=True)

n = int(input())
xl = [ list(myinput()) for _ in range(n) ]

ls = []
for i in range(n):
    x = xl[i][0]
    l = xl[i][1]
    s = x - l
    e = x + l
    d= [s,e]
    ls.append(d)
# print(ls)
ls.sort(key=lambda x:x[1],reverse=False)
# print(ls)

count = 0
e = -1*float("inf")
for i in range(n):
    ns,ne = ls[i]
    if ns>=e:
        count += 1
        e = copy(ne)
    else:
        pass

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
ts=[]
for i in range(N):
  x, l = map(int,input().split())
  if x + l <= 10**9:
    t = x + l
  else:
    t = s
  if x-l >= 0:
    s = x-l
  else:
    s = 0
  ts.append([t,s])
ts.sort()

count = 0
lastT = 0
for i in ts:
  if i[1]>=lastT:
    count+=1
    lastT=i[0]
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
ts=[]
for i in range(N):
  x, l = map(int,input().split())
  if x + l <= 100000:
    t = x + l
  else:
    t = s
  if x-l >= 0:
    s = x-l
  else:
    s = 0
  ts.append([t,s])
ts.sort()

count = 0
lastT = 0
for i in ts:
  if i[1]>=lastT:
    count+=1
    lastT=i[0]
print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 998244353
#define MAX 100
#define INF 800000000

int main(){
  int N;
  cin>>N;
  vector<pair<ll,ll>> X(N);
  for(int i=0;i<N;i++){
    ll x,l;
    cin>>x>>l;
    X.at(i).first=x-l;
    X.at(i).second=x+l;
  }
  sort(X.begin(),X.end());

  int ans=0;
  int k=0;
  while(1){
    int j=k;
    for(int i=k;i<N;i++){
      if(X.at(i).second<X.at(j).second){
        j=i;
      }
    }
    pair<ll,ll> p=make_pair(X.at(j).second,-2000000000);
    k=lower_bound(X.begin(),X.end(),p)-X.begin();
    ans++;
    if(k==N){
      break;
    }
  }
  cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
Y = [list(map(int,input().split())) for _ in range(n)]
X = []
for y in Y:
    X.append(y[0]-y[1],y[0]+y[1])
X.sort()
ans = n
right = X[0][1]
for i in range(1,n):
    left = X[i][0]
    if left < right:
        ans -= 1
    else:
        right = X[i][1]
print(ans)