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

import numpy as np

i_list = np.zeros((2,n), dtype = int)

for i in range(n):
  i_list[0,i], i_list[1,i] = map(int, input().split())

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l - 1

for i in range(1, n):
  x = i_list_sorted[0, i]
  l = i_list_sorted[1, i]
  if x - l + 1 > l_max:
    ans+=1
    l_max = x + l -1
 
print(ans)

Submission status: Wrong Answer

Solution code:
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]) < 0:
        removed += 1
        x[i] = x[i-1]
        continue
    else:
        before = int(x[i][0]) - int(x[i][1])
    if (int(x[i-1][0]) + int(x[i-1][1])) > 1000000000:
        removed += 1
        x[i] = x[i-1]
        continue
    else:
        after = int(x[i-1][0]) + int(x[i-1][1]) 
    if before < after:
        removed += 1
        if (int(x[i][0]) + int(x[i][1])) > (int(x[i-1][0]) + int(x[i-1][1])):
            x[i] = x[i-1]

print(n - removed)

Submission status: Wrong Answer

Solution code:
import bisect
from collections import deque
import sys
input = sys.stdin.readline
N =int(input())
p = 0
XL = [list(map(int,input().split())) for i in range(N)]
ans = []
ans2 = []
for i in range(N):
    ans.append([XL[i][0]-XL[i][1], XL[i][0]+XL[i][1]])
for i in range(N):
    ans2.append([XL[i][0]+XL[i][1], XL[i][0]-XL[i][1]])
t = deque([ans[i][0] for i in range(N)])
tt = deque([ans2[i][0] for i in range(N)])
ans.sort()
ans2.sort()
s = []
for i in range(N-1):
    s.append(bisect.bisect_left(t,ans[i][1])-1)
    t.popleft()
s.append(0)
k = N
for i in range(1, N):
    s[-i] += (k - bisect.bisect_right(tt,ans2[-i][1])-1)
    k -= 1
    tt.pop()
s.sort()
pp = sum(s)
k = N
if pp == 0:
    print(N)
    sys.exit()
for i in range(N):
    pp -= 2*s[-i-1]
    if pp <= 0:
        print(N-i-1)
        break

Submission status: Wrong Answer

Solution code:
n = int(input())

count = 0
X = []

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

for i in range(n-1):
    if X[i][0] + X[i][1] > X[i+1][0]:
        count += 1
        i += 1
    
print(n-count)

Submission status: Wrong Answer

Solution code:
n = int(input())

import numpy as np

i_list = np.zeros((2,n), dtype = int)

for i in range(n):
  i_list[0,i], i_list[1,i] = map(int, input().split())

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l - 1

for i in range(1, n):
  x = i_list_sorted[0, i]
  l = i_list_sorted[1, i]
  if x - l + 1 > l_max:
    ans+=1
    l_max = x + l -1
  elif (x + 1 == i_list_sorted[0, i-1]) and (x - l + 1 == l_max):
    ans+=1
    # l_max = x + l -1
 
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=0
ans2=0
cnt=-(10**9)-1
cnt2=(10**9)*2
li=[]
li2=[]
for i in range(n):
    X,L=map(int,input().split())
    li.append([X-L,L])
    li2.append([X+L,L])
li=sorted(li,key=lambda x:x[0])
for i in range(n):
    if cnt>li[i][0]:
        ans+=1
    else:
        cnt=li[i][0]+li[i][1]*2
li2=sorted(li2,key=lambda x:x[0],reverse=True)
for i in range(1,n):
    if cnt2<li[i][0]:
        ans2+=1
    else:
        cnt2=li[i][0]-li[i][1]*2
print(n-min(ans,ans2))

Submission status: Wrong Answer

Solution code:
n = int(input())

import numpy as np

i_list = np.zeros((2,n), dtype = int)

for i in range(n):
  i_list[0,i], i_list[1,i] = map(int, input().split())

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l - 1

for i in range(1, n):
  x = i_list_sorted[0, i]
  l = i_list_sorted[1, i]
  if x - l + 1 > l_max:
    ans+=1
    l_max = x + l -1
  elif (x + 1 == i_list_sorted[0, i-1]) and (x - l + 1 == l_max):
    ans+=1
    l_max = x + l -1
 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xl = [list(map(int, input().split())) for _ in range(N)]
xl.sort(key=lambda x: x[0])
cnt = 1
tmp1 = xl[0][0] + xl[0][1]
for i in range(1, N):
    tmp2 = xl[i][0] - xl[i][1]
    if tmp2 >= tmp1:
        cnt += 1
        tmp1 = xl[i][0] + xl[i][1]

print(cnt)

Submission status: Wrong Answer

Solution code:

N = int(input())
list = [[0] * 2] * N

for i in range(N):
    list[i] = [int(e) for e in input().split()]
list.sort()

j = N
dk = N - 1
i = 1
if N < 3:
    print(j)
else:
    while i < dk:
        a = list[i - 1][0]
        b = list[i - 1][1]
        c = list[i][0]
        d = list[i][1]
        e = list[i + 1][0]
        f = list[i + 1][1]
        if ((a + b) > (c - d)) and ((c + d) > (e - f)):
            del(list[i])
            j = j - 1
            dk = dk - 1
            i = 1
        i = i + 1
    print(j)

Submission status: Wrong Answer

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
xl = []
for i in range(n):
    xx,ll = inm()
    xl.append((xx,ll))
xl.sort()
x = [z[0] for z in xl]
l = [z[1] for z in xl]


#ddprint(x)
#ddprint(l)

ok = [1]*n

for i in range(n-1):
    if x[i]+l[i] < x[i+1]+l[i+1]:
        break
    else:
        ok[i] = 0

while i<n-1:
    for j in range(i+1,n):
        if x[i]+l[i] > x[j]-l[j] and (j==n-1 or x[j]+l[j]<x[j+1]+l[j+1]):
            ok[j] = 0
        else:
            break
    i = j

print(sum(ok))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

l=l[np.argsort(x)]
x=np.sort(x)

ans=np.zeros(n)+1

for i in range(n-1):
  if x[i]+l[i]+l[i+1] > x[i+1] and ans[i] == 1:
    if i != n-2:
      if x[i+1]+l[i+1]+l[i+2] > x[i+2]:
        ans[i+1] = 0
      else:
        if l[i] > l[i+1]:
          ans[i] = 0
        else:
          ans[i+1] = 0
    else:
      if l[i] > l[i+1]:
        ans[i] = 0
      else:
        ans[i+1] = 0

print(int(np.sum(ans)))

Submission status: Wrong Answer

Solution code:
n = int(input())

import numpy as np

i_list = np.zeros((2,n), dtype = int)

for i in range(n):
  i_list[0,i], i_list[1,i] = map(int, input().split())

# print(np.argsort(i_list[0,:]))

i_list_sorted = i_list[:, np.argsort(i_list[0, :])]

# print(i_list_sorted)

ans = 1
x = i_list_sorted[0, 0]
l = i_list_sorted[1, 0]
l_max = x + l - 1

for i in range(1, n):
  x = i_list_sorted[0, i]
  l = i_list_sorted[1, i]
  if x - l + 1 > l_max:
    ans+=1
    l_max = x + l -1
  elif (x + 1 == i_list_sorted[0, i-1]) and (x - l + 1 >= l_max):
    ans+=1
    l_max = x + l -1
 
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
R = N
X = []
L = []
for i in range(N):
  x, l = map(int, input().split())
  X.append(x)
  L.append(l)
if N == 1:
  print(1)
else:
  for j in range(0, N-1):
    right = L[j] + L[j]
    left = L[j+1] - L[j+1]
    dis = X[j+1] - X[j]
    if left > dis or right > dis:
      R -= 1
  print(R)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
n = int(input())
xl = []
ans = 0
for i in range(n):
  xl.append(list(map(int, input().split())))
  xl.sort(key = lambda x:x[1])
  location = xl[0][0]
  arm = xl[0][1]
  road = [j for j in range(location-arm+1, location+arm)]
for i in range(n):
  sub = []
  location = xl[i][0]
  arm = xl[i][1]
  A = bisect.bisect_left(road, location)
  if A == 0:
    if road[A]-location>=arm:
      for j in range(location-arm+1, location+arm):
        road.append(j)
      road.sort()
      ans += 1
  elif A == len(road):
    if location-road[A-1]>=arm:
      for j in range(location-arm+1, location+arm):
        road.append(j)
      road.sort()
      ans += 1
    else:
      if min(location-road[A-1], road[A]-location)>=arm:
        for j in range(location-arm+1, location+arm):
          road.append(j)
      road.sort()
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    N = int(input())
    xs = [0] * N
    ls = [0] * N
    left = [0] * N
    right = [0] * N
    for i in range(N):
        xs[i], ls[i] = [int(x) for x in input().split()]
        left[i] = xs[i] - ls[i]
        right[i] = xs[i] + ls[i]
    ret = 1
    xs_argsorted = np.argsort(xs)
    left_as = np.argsort(left)
    right_as = np.argsort(right)
    # print("DONE!!")

    score = [0] * N
    for i in range(N):
        nl = bisect_right(right_as, left[i]) - i - 1
        nr = bisect_left(left_as, right[i]) - i - 1
        score[i] = nl + nr
    return np.sum(score) - N

    line_right = [0] * N
    line_N = [0] * N
    max_line = 0
    for i in range(N):
        ind = xs_argsorted[i]
        flag = False
        for j in range(max_line):
            if line_right[j] <= xs[ind] - ls[ind]:
                line_right[j] = xs[ind] + ls[ind]
                line_N[j] += 1
                flag = True
        if not flag:
            max_line += 1
            line_right[max_line - 1] = xs[ind] + ls[ind]
            line_N[max_line - 1] = 1
        # print(line_right, line_N)
    return np.max(line_N)


    ls_argsorted = np.argsort(ls)
    left.sort()
    right.sort()
    # lf_sorted = sort(left)
    # ri_sorted = np.sort(right)
    print(xs, ls)
    print(xs_argsorted, ls_argsorted)
    ret = 0
    for i in range(N):
        ind = ls_argsorted[N-1-i]
        x = xs[ind]
        l = left[ind]
        r = right[ind]
        print(x, ls[ind], bisect_right(left, l), bisect_left(right, r))
        if bisect_right(left, l) == N and bisect_left(right, r) == 0:
            ret += 1

    return ret


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
l=[]
w=[]
max=-(10**10)
num=0
for i in range(n):
    X,L=map(int,input().split())
    x.append(X)
    l.append(L)
    w.append(X-L)
    w.append(X+L)
for i in range(len(w)):
    if (w[i]<max) and i%2==0:
        num+=1
    elif (w[i]<max) and i%2==1:
        num+=0
    else:
        max=w[i]
print(len(w)-num)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

l=l[np.argsort(x)]
x=np.sort(x)

ans=np.zeros(n)+1

for i in range(n-1):
  if x[i]+l[i]+l[i+1] > x[i+1] and ans[i] == 1:
    if i != n-2:
      if x[i+1]+l[i+1]+l[i+2] > x[i+2]:
        ans[i+1] = 0
      else:
        if l[i] > l[i+1]:
          ans[i] = 0
        else:
          ans[i+1] = 0
    else:
      if l[i] > l[i+1]:
        ans[i] = 0
      else:
        ans[i+1] = 0

print(np.sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
XList = []
LList = []

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

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


for i in range(0, N - 1):
    for q in range(i + 1, N):
        if XList[i] + LList[i] > XList[q] - LList[q]:
            tmpList.append(q)

AndList = set(resultList) ^ set(tmpList)
 
print(len(AndList) + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
MAX_list = []
ans = 0
A = -10**9

for _ in range(N):
    X, L = map(int, input().split())
    MAX_list.append(((X + L - 1), (X - L + 1)))
MAX_list = sorted(MAX_list)

for m, l in MAX_list:
    if l > A:
        ans += 1
        A = m

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
n=int(input())
lst=[]
for i in range(n):
  x,l=map(int,input().split())
  lst.append([x,l])
lst.sort(key=lambda x:(x[1]-x[0]))
if n==1:
    print(1)
    sys.exit()
if n==2:
    if lst[1][0]-lst[1][1]<lst[0][0]+lst[0][1]:
        print(2)
        sys.exit()
    else:
        print(1)
        sys.exit()
Lst=[0]*n
hani=[]
for i in range(n):
  hani.append(lst[i][0]-lst[i][1]+0.5)
hani.sort()
for i in range(n):
  idx=bisect.bisect_left(hani,lst[i][0]+lst[i][1])
  Lst[i]+=idx-i-1
  for j in range(i+1,idx):
    Lst[j]+=1
cnt=0
for k in range(n):
  if Lst[k]>0:
    cnt+=1
print(n-(cnt//2)+1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())

X_t=[]
L_t=[]
ans=0

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)
    

nls=[0]
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]):
        ans+=1
    else:
        nls.append(i)
nls.append(N-1)
        
for i in range(len(nls)-1):
    if nls==[]:
        break
    if len(nls)==1:
        break
    if (i-2)>len(nls):
        break
    
    if X[nls[i]]+L[nls[i]]>X[nls[i+1]]-L[nls[i+1]]:
        ans+=1

nls.sort()
if X[nls[-1]]-L[nls[-1]]<X[nls[-2]]+L[nls[-2]]:
    ans+=1
print(N-ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from bisect import bisect_right

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

r=[]
l=[]
m=10**9
for x,ll in list:
 r.append(x-ll+1)
 l.append(x+ll-1)
 m=min(m,x+ll-1)

cnt=1
inx1=bisect_left(r,m)
b_inx=inx1
inx2=0
while inx1<n:
 inx2=bisect_right(r,l[inx1])
 inx1=r.index(min(r[inx1:inx2+1]))+1
 if inx1==b_inx:
  break
 else:
  b_inx=inx1
  cnt+=1

print(min(cnt,n))

Submission status: Wrong Answer

Solution code:

N = int(input())
list = [[0] * 2] * N

for i in range(N):
    list[i] = [int(e) for e in input().split()]
list.sort()

j = N
dk = N - 1
i = 1
if N < 3:
    print(j)
else:
    while i < dk:
        a = list[i - 1][0]
        b = list[i - 1][1]
        c = list[i][0]
        d = list[i][1]
        e = list[i + 1][0]
        f = list[i + 1][1]
        i = i + 1
        if ((a + b) > (c - d)) and ((c + d) > (e - f)):
            del(list[i])
            j = j - 1
            dk = dk - 1
            i = 1
    print(j)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

sorted_data = sorted(dist,key=lambda x:(x[0],x[1]))
#print(sorted_data)

remove = 0
temp = sorted_data[0]
for i in range(1,n):
    d = sorted_data[i][0]-temp[0]
    if d <= temp[1]:
        temp = sorted_data[i]
        remove += 1
        #print("rv:", sorted_data[i][0], sorted_data[i][1])

print(n-remove)

Submission status: Wrong Answer

Solution code:
N = int(input())


times = 1

xls = [0]*N

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

xls.sort()

interval = (xls[0][0] - xls[0][1] + 1, xls[0][0] + xls[0][1] - 1)

for i in range(1, N):
    newinterval = (xls[i][0] - xls[i][1] + 1, xls[i][0] + xls[i][1] - 1)
    if interval[1] < newinterval[0]:
        times += 1
    interval = (interval[0], newinterval[1])

print(times)

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()
    #print(xls_input)

    xls = []
    ans = N
    seq = 0
    i = 0
    while i <= N - 1:
        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 seq == 0:
                if x - x_before < l + l_before:
                    ans -= 1
                    seq = 1
                else:
                    xls.append(xl)
                    seq = 0
            elif seq == 1:
                if x - x_before < l + l_before:
                    del xls[-1]
                    xls.append(xls_input[i-1])
                    i -= 1
                    seq = 0
                else:
                    xls.append(xl)
                    seq = 0   
        #print(xls)    
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
move = []
for i in range(N):
    X,L = map(int,input().split())
    move.append([X-L,X+L])
move = sorted(move, key=lambda x:(x[0],x[1]))

i = 1
while(len(move) > i+1):
    if move[i-1][0] == move[i][0]:
        del move[i-1]
    else:
        if move[i+1][0] <= move[i-1][1]:
            del move[i]
        else:
            i += 1
    if move[len(move)-2][1] >= move[len(move)-1][1]:
        print(len(move)-1)
    else:
        print(len(move))

Submission status: Wrong Answer

Solution code:
N = int(input())
robot = []

for i in range(N):
    x,l = map(int,input().split())
    robot.append([x,l])
    
robot.sort()
use = [0]*N
i = 0

while i < N-1:
    #print(i,"called")
    min_j = i
    min_pos = robot[i][0] + robot[i][1]
    if (robot[i][0] + robot[i][1]) <= (robot[i+1][0] - robot[i+1][1]):
        #print(i, "pass")
        use[i] = 1
        if i == N-2:
            use[N-1] = 1
            break
        i += 1

    else:
        for j in range(i+1,N):
            if (robot[i][0] + robot[i][1]) <= (robot[j][0] - robot[j][1]):
                break
            else:
                if min_pos > robot[j][0] + robot[j][1]:
                    min_pos = robot[j][0] + robot[j][1]
                    min_j = j
        use[min_j] = 1
        #print(i, min_j, j)
        if i == min_j:
            if j != N-1:
                i = j
            else:
                if min_pos <= robot[N-1][0]-robot[N-1][1]:
                    use[N-1] = 1
                    break
                else:
                    break
        else:
            i = min_j
        

print(sum(use))
#print(use)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

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

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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(N, XL):
    s = []
    for x, l in XL:
        lp, rp = x-l+1, x+l-1
        s.append((lp, rp))

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

    ans = 0
    t = -INF
    for l, r in s:
        if t <= l:
            ans += 1
            t = r

    return ans

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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 ii, i in enumerate(xs[1:]):
    start = scope[i][0]
    if end <= start:
        ans += 1
        end = start
    else:
        if scope[i][1] <= scope[xs[ii+1]][0] and ii+1 <= n:
            ans += 1
            end = scope[xs[ii+1]][1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
move = []
for i in range(N):
    X,L = map(int,input().split())
    move.append([X-L,X+L])
move = sorted(move, key=lambda x:(x[0],x[1]))

while(len(move) > i+1):
    if move[i-1][0] == move[i][0]:
        del move[i-1]
    else:
        if move[i+1][0] <= move[i-1][1]:
            del move[i]
        else:
            i += 1
    if move[len(move)-2][1] >= move[len(move)-1][1]:
        print(len(move)-1)
    else:
        print(len(move))

Submission status: Wrong Answer

Solution code:

n = int(input())

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

sorted_data = sorted(dist,key=lambda x:(x[0],x[1]))
#print(sorted_data)

remove = 0
temp = sorted_data[0]
for i in range(1,n):
    d = sorted_data[i][0]-temp[0]
    if d < temp[1]:
        temp = sorted_data[i]
        remove += 1
        #print("rv:", sorted_data[i][0], sorted_data[i][1])

print(n-remove)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = [[0,0]] * n
x_max = 10**9

for i in range(n):
  x, l = map(int, input().split())
  r[i] = [x, l]
# print(r)
r.sort()
# print(r)

ans = 0
end = -1
for i in range(n):
  if end == x_max:
    break
  
  x = r[i][0]
  l = r[i][1]
  current_start = x - l + 1
  if current_start < 0:
    current_start = 0
  
  current_end = x + l - 1
  if current_end > x_max:
    current_end = x_max
  
  ans += 1
  if end == -1:
    # first robot
    end = current_end
    continue
  if current_start <= end:
    ans -= 1
    if current_end < end:
      end = current_end
  else:
    end = current_end
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

X_t=[]
L_t=[]
ans=0

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)
    

nls=[0]
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]):
        ans+=1
    else:
        nls.append(i)
nls.append(N-1)
        
for i in range(len(nls)-1):
    if nls==[]:
        break
    if len(nls)==1:
        break
    if (i-2)>len(nls):
        break
    
    if X[nls[i]]+L[nls[i]]>X[nls[i+1]]-L[nls[i+1]]:
        ans+=1

if X[nls[-1]]-L[nls[-1]]<X[nls[-2]]+L[nls[-2]]:
    ans+=1
print(N-ans)

Submission status: Wrong Answer

Solution code:
# 息がかかっていないところから貪欲
N = int(input())
robots = [(-10**11, 0)]
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x, l))

robots.append((10**12, 0))
robots = sorted(robots, key=lambda x: x[0])

for i in range(1, len(robots)-1):
    if robots[i][0] + robots[i][1] - 1 < robots[i+1][0] - robots[i+1][1] + 1:
        hoge = i
        break
# 初めて隣に迷惑をかけていない人
rightest_point = robots[hoge][0] + robots[hoge][1] - 1
ans = 0
for j in range(hoge+1, len(robots)):
    if robots[j][0]-robots[j][1] + 1 < rightest_point:
        ans += 1
        continue
    else:
        rightest_point = robots[hoge][0]+robots[hoge][1] - 1

third = N-hoge-ans+1


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
X = []
L = []
for i in range(N):
    a, b = map(int,input().split())
    X.append(a)
    L.append(b)
l = dict()
for i in range(N):
    l[X[i]] = L[i]
X.sort()
R = dict()
flag = dict()
for i in range(N):
    R[X[i]] = X[i] + l[X[i]]
    R[-X[i]] = X[i] - l[X[i]]
    flag[X[i]] = 0

for i in range(1,N-1):
    if i > 1:
        #3個以上侵食する奴ら
        if (R[X[i-2]] > R[-X[i]]): #or (R[X[i]] > R[-X[i+2]]):
            flag[X[i]] = 2
            continue
    if i < (N-3):
        if (R[X[i]] > R[-X[i+2]]):
            flag[X[i]] = 2
            continue
    #2個以上侵食する奴ら
    if (R[X[i-1]] > R[-X[i]]) and (R[X[i]] > R[-X[i+1]]):
        flag[X[i]] = 2
        continue
        #1個侵食する奴ら
    if (R[X[i-1]] > R[-X[i]]) or (R[X[i]] > R[-X[i+1]]):
        if flag[X[i]] == 0:
            flag[X[i]] = 1
#X[0]とX[N-1]の扱い
lenx = len(X)
if lenx > 2:
    if R[X[0]] > R[-X[2]]:
        flag[X[0]] = 2
if lenx > 1:
    if R[X[0]] > R[-X[1]]:
        if flag[X[0]] == 0:
            flag[X[0]] = 1
if lenx > 2:
    if R[X[N-3]] > R[X[N-1]]:
        flag[X[N-1]] = 2
if lenx > 2:
    if R[X[N-2]] > R[X[N-1]]:
        if flag[X[N-1]] == 0:
            flag[X[N-1]] = 1
while(1):
    fl = 0
    del2_list = []
    del2 = 0
    for i in range(len(X)):
        if flag[X[i]] != 2:
            del2_list.append(X[i])
        else:
            del2 = 1
            flag[X[i]] = -1
    if del2 > 0:
        X = del2_list
        X.sort()
    del1_list = []
    del1 = 0
    if del2 == 0:
        for i in range(len(X)-1):
            on_off = 1
            if flag[X[i]] != 1:
                del1_list.append(X[i])
            else:
                if flag[X[i+1]] == 1:
                    if R[X[i]] > R[-X[i+1]]:
                        del1_list.append(X[i])
                        on_off = 0
                del1 = 1
                if on_off:
                    flag[X[i]] = -1
        lenx = len(X)
        #len(X)-1の処理
        if lenx > 0:
            if flag[X[len(X)-1]] != 1:
                del1_list.append(X[len(X)-1])
            else:
                del1 = 1
                flag[X[len(X)-1]] = -1
        if del1 > 0:
            X = del1_list
            X.sort()


    R_2 = dict()
    for i in range(len(X)):
        R_2[X[i]] = X[i] + l[X[i]]
        R_2[-X[i]] = X[i] - l[X[i]]
        flag[X[i]] = 0
    for i in range(1,len(X)-1):
        if (R_2[X[i-1]] > R_2[-X[i]]) or (R_2[X[i]] > R_2[-X[i+1]]):
            flag[X[i]] = 1
    if len(X) > 1:
        if R_2[X[0]] > R_2[-X[1]]:
            flag[X[0]] = 1
    if len(X) > 2:
        if R_2[X[len(X)-2]] > R_2[-X[len(X)-1]]:
            flag[X[len(X)-1]] = 1

    for i in range(len(X)):
        if flag[X[i]] > 0:
            fl = 1
            break
    if fl == 0:
        break
ans = len(X)
#if ans == 0:
#    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
l = []
for i in range(N):
    x1,l1=[int(i) for i in input().split()]
    x.append(x1)
    l.append(l1)

Range = []

for i in range(N):
  max_i = x[i] + l[i]
  min_i = x[i] - l[i]
  Range.append((min_i,max_i,x[i]))

Range = sorted(Range, key = lambda x:x[2])

#print(Range)
a = 1

for i in range(N-1):
  #print(Range[a][0], end = ","),print(Range[a-1][1])
  if Range[a][0] >= Range[a-1][1]:
    a += 1
  else:
    Range.pop(a)

#print(Range)
print(a)