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: Runtime Error

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import sys
input = sys.stdin.readline

n = int(input())

xl = []
for i in range(n):
    z = list(map(int, input().split()))
    z.append(0)
    xl.append(z)

xl.sort()
cnt=0

if xl[1][0]-xl[1][1]-(xl[0][0]+xl[0][1])<0:
    xl[1][2]=1
    cnt+=1
    #print(cnt)
if xl[-2][0]-xl[-2][1]-(xl[-1][0]+xl[-1][1]) < 0:
    xl[-2][2]=1
    cnt += 1
    #print(cnt)

for i in range(2,n-3):
    if xl[i+1][0]-xl[i+1][1]-(xl[i][0]+xl[i][1]) < 0 and xl[i][2]!=1 and xl[i][2]!=1:
        xl[i+1][2]=1
        cnt += 1
        #print(cnt)
print(n-cnt+1)

Submission status: Runtime Error

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import sys
input = sys.stdin.readline

n = int(input())

xl = []
for i in range(n):
    z = list(map(int, input().split()))
    z.append(0)
    xl.append(z)

xl.sort()
cnt=0

if xl[1][0]-xl[1][1]-(xl[0][0]+xl[0][1])<0:
    xl[1][2]=1
    cnt+=1
    print(cnt)
if xl[-2][0]-xl[-2][1]-(xl[-1][0]+xl[-1][1]) < 0:
    xl[-2][2]=1
    cnt += 1
    print(cnt)

for i in range(2,n-3):
    if xl[i+1][0]-xl[i+1][1]-(xl[i][0]+xl[i][1]) < 0 and xl[i][2]!=1 and xl[i][2]!=1:
        xl[i+1][2]=1
        cnt += 1
        print(cnt)
print(n-cnt+1)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    long long n;
    std::cin >> n;

    std::vector<std::pair<long long, long long>> robots(n);
    for (int i = 0; i < n; i++) {
        std::cin >> robots[i].first >> robots[i].second;
    }

    std::vector<std::pair<long long, long long>> rightset(n);
    for (int i = 0; i < n; i++) {
        rightset[i].first = robots[i].first + robots[i].second;
        rightset[i].second = i;
    }

    std::sort(rightset.begin(), rightset.end(), std::greater<std::pair<long long, long long>>());

    long long count = n;
    long long current_idx = rightset[0].second;
    for (int i = 1; i < n; i++) {
        if (robots[current_idx].first - robots[current_idx].second >= rightset[i].first) {
            current_idx = rightset[i].second;
        } else {
            count--;
        }
    }

    std::cout << count << std::endl;
}

Submission status: Runtime Error

Solution code:
N = int(input())
a = sorted([(x + l, x - l) for x, l in (map(int, l.split()) for l in sys.stdin)])

last = a[0][0]
ans = 1

for r, l in a[1:]:
    if last <= l:
        ans += 1
        last = r

print(ans)

Submission status: Runtime Error

Solution code:
int(input())
A = [list(map(int,input().split())) for i in list(range(N))]
B = [[i[0]+i[1], i[0]-i[1]] for i in A]
B.sort()
prev=B[0]
cnt=N
for i in range(1,N):
  if prev[0]<B[i][1]:
    cnt-=1
  else:
    prev=B[i]
print(cnt)

Submission status: Runtime Error

Solution code:
int(input())
A = [list(map(int,input().split())) for i in list(range(N))]
B = [[i[0]+i[1], i[0]-i[1]] for i in A]
B.sort()
prev=B[0]
cnt=N
for i in range(1,N):
  if prev[0]<B[i][1]:
    nt-=1
  else:
    prev=B[i]
print(cnt)

Submission status: Runtime Error

Solution code:
 int(input())
A = [list(map(int,input().split())) for i in list(range(N))]
B = [[i[0]+i[1], i[0]-i[1]] for i in A]
B.sort()
prev=B[0]
cnt=N
for i in range(1,N):
  if prev[0]<B[i][1]:
    nt-=1
  else:
    prev=B[i]
print(cnt)

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    C = []
    for _ in range(N):
        a, b = list(map(int, input().split()))
        C.append((a-b+1, a+b-1))

    C.sort()

    for i in range(len(C)-1):
        if C[i][1] > C[i+1][0]:
            C.pop(0)

    return len(C)

print(solve())

Submission status: Runtime Error

Solution code:
def duplicate(x):
  f = list()
  for i in range(len(x)):
    f.append(0)

  for i in range(len(x)-1):
    if x[i][0] + x[i][1] > x[i+1][0] - x[i+1][1]:
      f[i] += 1
      f[i+1] += 1

  return f
    

n = int(input())
x = list()
for i in range(n):
  x.append(list(map(int,input().split())))
  
x.sort()

c = 0
counter = 0
f = list()

while True:
  f = duplicate(x)
  for i in range(len(f)-1):
    if f[i] == 1 and f[i+1] == 2:
      x.pop(i+1)
      counter += 1
    elif f[i] == 1 and f[i+1] == 1:
      if x[i][1] > x[i+1][1]:
        x.pop(i)
        counter += 1
      else:
        x.pop(i+1)
        counter += 1
    elif f[i] == 2 and f[i+1] == 2:
      if x[i][1] > x[i+1][1]:
        x.pop(i)
        counter += 1
      else:
        x.pop(i+1)
        counter += 1
  
  if sum(f)==0:
    break
    
print(len(x))

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:

n = int(input())
m_list = []
for i in range(n):
  X, L = map(int, input().split())
  m_list.append([X-L,X+L])

m_list = sorted(m_list)
  
def MachineArrangementCheck():
  length = len(Machine_list)
  # 配列の上限エラー対策
  for i in range(length):
    if i != length - 1:      
      # m1の上限とm２の下限が接するかを確認
      if (m_list[i][1] - m_list[i+1][0]) < 0:
        del m_list[i+1]
        return False
  return True

while MachineArrangementCheck() == False:
  continue
  
print(len(m_list))

Submission status: Runtime Error

Solution code:
class Robot:
    def __init__(self, left, right):
        self.left = left
        self.right = right
    
    def __lt__(self, other):
        return self.right < other.right

n = int(input().rstrip())
robos = [None] * n

for i in range(n):
    line = input().rstrip().split(' ')
    robos[i] = Robot(int(line[0]) - int(line[1]), int(line[0]) + int(line[1])

robos.sort()

cur = -1000000000
ans = 0
for i in range(n):
    if cur <= robos[i].left:
        ans += 1
        cur = robos[i].right

print(ans)

Submission status: Runtime Error

Solution code:
num = input()
robots = []
for i in range(num):
  robots.append([input().split()])
print(robots)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
count = 0
for i in range(n):
    x_l = list(map(int,input().split()))
    a.append(x_l)
    
for j in range(n-1):
    if (a[j[0]] + a[j[1]]) > (a[j+1[0]] - a[j+1[1]]):
        count += 1
        a[j+1[0]] = a[j[0]]
        a[j+1[1]] = a[j[1]]

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
count = 0
for i in range(n):
    x_l = list(map(int,input().split()))
    a.append(x_l)
    
for j in range(n-1):
    if (a[j[0]] + a[j[1]]) > (a[j+1[0]] - a[j+1[1]]):
        count += 1
        a[j+1[0]] = a[j[0]]
        a[j+1[1]] = a[j[1]]

print(count())

Submission status: Runtime Error

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

count=0
base=[]

for i in range(N):
    sumple=list(range(XL[i][0]-XL[i][1]+1,XL[i][0]+XL[i][1]))
    for j in range(len(sumple)):
        if sumple[j] in base:
            count+=1
            break
        else:
            if j == len(sumple)-1:
                for k in range(len(sumple)):
                    base.append(sumple[k])

#print(base)
print(N-count)

Submission status: Runtime Error

Solution code:
N = int(input())
X = []
ans = 0
pre = 0
i = 0
while i < N:
    x, l = input().split()
    X.append([int(x), int(l)])

    # j=0
    # while j < len(X):
    #     if X[j][0] > int(x):
    #         X.insert(j, [int(x), int(l)])
    #         break
    #     elif j == len(X) -1:
    #         X.append([int(x), int(l)])
    #         break
    #     j+=1
    # if i == 0 : X.append([int(x), int(l)])
    i+=1

X.sort()
print(X)
i=0
while i < N:
    left = X[i][0] - X[i][1]
    right = X[i][0] + X[i][1]
    
    if left < pre and i != 0:
        ans += 1
    else
        pre = right
    
    i += 1
print(N - ans)

Submission status: Runtime Error

Solution code:
n=int(input())
ll=[]
for i in range(n):
  x,l=map(int,input().split())
  ll.append([x,l])
ll.sort()  
lll=ll[:]
for i in range(n-1):
  right=ll[i][0]+ll[i][1]-1
  left=ll[i+1][0]-ll[i+1][1]+1
  if right > left:
    lll.pop(i+1)
print(len(lll))

Submission status: Runtime Error

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()  
lll=ll[:]
for i in range(n-1):
  right=ll[i][0]+ll[i][1]-1
  left=ll[i+1][0]-ll[i+1][1]+1
  if right > left:
    lll.pop(i+1)
print(len(lll))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(a):
    x, l = map(int, input().split())
    A.append([x+l, x-l])
A.sort()
ans = 1
check1 = A[0]
for i in range(1, N):
    check2 = A[i]
    if check1[0] <= check2[1]:
        ans += 1
        check1 = check2
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

#N, M = map(int, input().split())
N = int(input())

mt = np.zeros([N, 3000000])
for i in range(N):
    x, l = map(int, input().split())
    mt[i,max(0,x-l):x+l] = 1

flag = 1    
if np.max(np.sum(mt, axis=0))==1:
    flag = 0
# print(mt)    
cnt = 0
while flag:
    cnt += 1
    tmp = np.sum(mt, axis=0)
    ID = np.argmax(tmp)
    tmp_max = 0
    tmp_id = -1
    for i in reversed(range(N)):
        if mt[i, ID] == 1:
            # print(tmp_id, ID, mt[i],mt)
            a = np.sum(mt[i])
            if  a > tmp_max:
                tmp_max = a
                tmp_id = i

    mt[tmp_id] = 0
    #         np.delete(mt, i, 0)
    # mt[mt[:, ID] == 1] = 0
    # print(np.sum(mt, axis=0), np.max(np.sum(mt, axis=0)))
    if np.max(np.sum(mt, axis=0))==1:
        flag = 0
            
print(N- cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
y = np.array([
    list(map(int, input().split())) for i in range(n)
])
robot = sorted(y, key=lambda x: x[1])
ans = np.array()
now = set()

for i in range(1, n):
    robot_i = robot[0]
    robot = robot[1:]
    i_range = set(np.arange(
        robot_i[0] - robot_i[1], robot_i[0] + robot_i[1]
    ))
    if len(now.intersection(i_range)) == 0:
        now = now.union(i_range)
        np.append(ans, robot_i)
print(len(ans))

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
b=[]
for i in a:
	ma=i[0] + i[1]
	mi=i[0] - i[1]
	c=[mi,ma]
	b.append(c)


while True:
	count=[]
	for i in range(n):
		count.append(0)
	p=0
	d=list(itertools.combinations(range(n), 2))
	for i in d:
		p+=1
		if b[i[0]][0]<b[i[1]][0]<b[i[0]][1] or b[i[0]][0]<b[i[1]][1]<b[i[0]][1]:
			count[i[0]]+=1
			count[i[1]]+=1
	del b[count.index(max(count))]
	del b[count.index(max(count))]
	print(count)
	n-=1
	if sum(count)==0:
		break
print(len(count))

Submission status: Runtime Error

Solution code:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

// IO struct
type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func newIO() *IO {
	return &IO{
		scanner: bufio.NewScanner(os.Stdin),
		writer:  bufio.NewWriter(os.Stdout),
	}
}

func (IO *IO) nextLine() string {
	IO.scanner.Scan()
	return IO.scanner.Text()
}

func (IO *IO) nextInt() int {
	i, e := strconv.Atoi(IO.nextLine())
	if e != nil {
		panic(e)
	}
	return i
}

func (IO *IO) nextInt64() int64 {
	a, _ := strconv.ParseInt(IO.nextLine(), 10, 64)
	return a
}

func (IO *IO) scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = IO.nextInt()
		nums = append(nums, num)
	}
	return
}

func (IO *IO) printLn(a ...interface{}) {
	fmt.Fprintln(IO.writer, a...)
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func sumSlice(nums []int) int {
	sum := 0
	for _, n := range nums {
		sum += n
	}
	return sum
}

func binarySearch(target int, list []int) int {
	left := 0
	right := len(list) - 1
	mid := (left + right) / 2

	for {
		if list[mid] < target {
			left = mid + 1
		} else {
			right = mid
		}
		mid = (left + right) / 2
		if left >= right {
			break
		}
	}
	return mid
}

// <<<<<<< functions for 2D array
type array2D [][]int

func (a array2D) Len() int {
	return len(a)
}

func (a array2D) Less(i, j int) bool {
	// return a[i][0] < a[j][0] // sort by 1st arg
	return a[i][1] < a[j][1] // sort by 2nd arg
}

func (a array2D) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a array2D) sort() {
	sort.Sort(a)
}

// >>>>>>> functions for 2D array

var io = newIO()

func main() {
	io.scanner.Split(bufio.ScanWords)       // switch to separating by space
	io.scanner.Buffer([]byte{}, 1000000009) // switch to read large size input
	defer io.writer.Flush()

	N := io.nextInt()
	robots := array2D{}

	for i := 0; i < N; i++ {
		x := io.nextInt()
		arm := io.nextInt()
		robot := []int{x, x + arm}
		robots = append(robots, robot)
	}

	robots.sort()
	count := 0
	lastR := int(-1e10)
	for _, robot := range robots {
		x := robot[0]
		r := robot[1]
		l := x - (r - x)
		if l < lastR {
			count++
		} else {
			lastR = r
		}
	}
	io.printLn(N - count)
}

Submission status: Runtime Error

Solution code:

N=int(input())
x = []
l = []
v = []
for _ in range(N):
    ix,il = input().split(" ")
    x.append(int(ix))
    l.append(int(il))
for _ in range(1000000):
    v.append(0)
for i in range(N):
    for j in range(max(0,x[i]-l[i]),x[i]+l[i]):
        v[j]=v[j]+1
print(N-(max(v)-1))

Submission status: Runtime Error

Solution code:
N=int(input())
x:int = []
l:int = []
v:int = []
for _ in range(N):
    ix,il = input().split(" ")
    x.append(int(ix))
    l.append(int(il))
for _ in range(1000000):
    v.append(0)
for i in range(N):
    for j in range(max(0,x[i]-l[i]),x[i]+l[i]):
        v[j]=v[j]+1
print(N-(max(v)-1))

Submission status: Runtime Error

Solution code:
#!/usr/loca/bin/python3

N=int(input())
x:int = []
l:int = []
v:int = []
for _ in range(N):
    ix,il = input().split(" ")
    x.append(int(ix))
    l.append(int(il))
for _ in range(1000000):
    v.append(0)
for i in range(N):
    for j in range(max(0,x[i]-l[i]),x[i]+l[i]):
        v[j]=v[j]+1
print(N-(max(v)-1))

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.eye(N, dtype=bool)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

LR = []
for i in range(N):
  X, L = map(int, input().split())
  LR.append([X-L, 1, i])
  LR.append([X+L, 0, i])

LR.sort()

tree = np.eye(N, dtype=bool)

is_now = np.zeros(N, dtype=bool)
for y, lr, idx in LR:
  if lr == 1:
    is_now[idx] = True
    tree[idx] += is_now
  else:
    is_now[idx] = False

tree += tree.T

a = np.sum(tree)
B = np.argsort(tree.sum(axis=0))[::-1]

Submission status: Runtime Error

Solution code:
n = int(input())

r = [[0, 0]] * n
for i in range(n):
   x, l = map(int, input().split())
   r[i] = [x-l, x+l]
r.sort()


while (1):
   ok = len(r)

   for i in range(0, len(r)):
      if (i==0):
         if (r[i][1] > r[i+1][0]):
            ok -= 1
            break
      elif (i==len(r)-1):
         if (r[i][0] > r[i-1][1]):
            ok -= 1
            break
      elif (r[i][0] > r[i-1][1] or r[i][1] > r[i+1][0]):
         ok -= 1
         break

   if (ok == len(r) or ok == 1):
      print(ok)
      exit()
   else:
      r.pop(i)

Submission status: Runtime Error

Solution code:
n = int(input())
arr = [list(map(int,input().split())) for i in range(n)]
arr.sort()
outcount = 0
#リストの数を減らすと最後の２つがぶつかってた場合が判定できない
#時間がかかりすぎ1回okだったところは次はパスしたい
outnum = 0
def saiki():
    global outcount
    global outnum
    for i in range(outnum, len(arr)-2):
        if arr[i][0] + arr[i][1] > arr[i+1][0] - arr[i+1][1]:#アウトの条件
            outcount += 1
            outnum = i-1
            if [i+1][0] + arr[i+1][1] <= arr[i+2][0] - arr[i+2][1]:#1つあとのやつがぶつかってるか
                arr.pop(i)
            else:
                arr.pop(i + 1)
            return 'no'


while saiki() == 'no':
    saiki()

print(n - outcount)

Submission status: Runtime Error

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,xx-ll))
xl.sort()

ddprint(xl)

cnt = 1
i = 0
while i<n:
    nxtj = -1
    for j in range(i+1,n):
        if xl[i][0]<=xl[j][1]:
            ddprint("j {} found".format(j))
            cnt += 1
            nxtj = j
            break
    i = nxtj if nxtj>0 else n
    ddprint("i {} j {} nxtj {}".format(i,j,nxtj))

print(cnt)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
X = []
for _ in range(N):
  x, l = map(int,input().split())
  X.append([x+l, x-l])
sorted_X = sorted(X, key=lambda x:(x[1], x[2]))
ans = 1
cnt = sorted_X[0][0]
for i in range(N):
  if sorted_X[i][1] >= cnt:
    ans += 1
    cnt = sorted_X[i][0]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
X=[]
for i in range(n):
    x,l=[int(_) for _ in input().split()]
    X+=[tuple(x-l,x+l)]
X.sort(key=lambda x:x[0])
ans=n
tmp=X[0][1]
for i in range(1,n):
    if tmp>X[i][0]:
        ans-=1
        tmp=min(tmp,X[i][1])
    else:
        tmp=X[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
inputs = sys.stdin.readlines()

n = int(inputs[1])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l, x+l))
Y.sort(key=lambda x: x[0])

cnt = 1
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 <= l:
        cnt += 1
        r0 = r
    
print(cnt)

Submission status: Runtime Error

Solution code:
s=int(input())
t=[]
for i in range(N):
    u,l = map(int,input().split())
    t.append((u-l,u+l-1))
t.sort(key=lambda x: x[1])
d=-10*10
ans=0
for i in range(s):
  a=t[i][0]-t[i][1]
  if d<a:
    ans+=1
    d=a+2*t[i][1]-1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(inputs[0])
Y = []
for s in inputs[1:]:
    x, l = map(int, s.split())
    Y.append((x-l+1, x+l-1))
Y.sort(key=lambda x: x[0])

cnt = 0
_, r0 = Y[0]
for i in range(1, n):
    l, r = Y[i]
    if r0 < l:
        cnt += 1
        r0 = r
print(cnt)

Submission status: Runtime Error

Solution code:
n, k, s = map(int, input().split())

for i in range(1, n+1):
    if i <= k:
        print(s)
    else:
        if s == 10**9:
            print(1)
        else:
            print(10**9)

Submission status: Runtime Error

Solution code:
N = int(input())
grid = []
checkflag = 0

for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

grid.sort()

if len(grid)>1:
    for j in range(len(grid)-1):
        if len(grid)-1==j:
            break
        while grid[j+1][0]-grid[j][0]<grid[j+1][1]+grid[j][1]:
            grid.pop(j+1)
            if len(grid)==1:
                break

print(len(grid))

Submission status: Runtime Error

Solution code:
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
list_N = list(range(1,N+1))
grid.sort()
a = 0
count = 0
for j in range(N) :
  list_a = list(range(grid[j][0]-grid[j][1]+1, grid[j][0]+grid[j][1]-1))
  list_b = list(set(list_a) - set(list_N))
  if list_b == []:
    list_N = list(set(list_N) - set(list_a))
    count += 0
  else:
    count += 1
print(N - count)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
grid = []
armbuffer = 0
checkflag = 0

for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

grid.sort()

# for j in range(len(grid), 0, -1):
#     if j == 1:
#         print(1)
#         break
#     for k in itertools.combinations(grid, j):
#         k = list(k)
#         for l in range(j - 1):
#             if k[l+1][0]-k[l][0]<k[l+1][1]+k[l][1]:
#                 break
#         else:
#             print(j)
#             break
#     else:
#         continue
#     break

aa = len(grid)

for j in range(len(grid)-1):
    if len(grid)-1==j:
        break
    while grid[j+1][0]-grid[j][0]<grid[j+1][1]+grid[j][1]:
        grid.pop(j+1)
        if len(grid)==1:
            break

print(len(grid))

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0
ans=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: Runtime Error

Solution code:
list=[]
i=0
j=0
r=0
n=int(input())

while i<n:
  i+=1
  a, b = map(int, input().split())
  list.append([a,b])

list.sort()

while i<n:
  i+=1
  a, b = map(int, input().split())
  list.append([a,b])

list.sort()

if(4<=n):
  while j<n-2:
    if(list[j][0]+listl[j][1] > list[j+1][0]-listl[j+1][1]):
      r+=1
      if(list[j+1][0]+list[j+1][1] > list[j+2][0]-list[j+2][1]):
        r-=1
    j+=1

  if(list[n-2][0]+list[n-2][1] > list[n-1][0]-list[n-1][1]):
    r+=1
    if(list[n-1][0]+list[n-1[1]] > list[n][0]-list[n][1]):
      r-=1
    if(list[n-2][0]+list[n-2[1]] > list[n][0]-list[n][1]):
      r+=1
print(n-r)

Submission status: Runtime Error

Solution code:
from functools import lru_cache

@lru_cache(maxsize=1000)
def judge(x,L):
    for l in L:
        if x[1]>l[0] and x[0] <l[1]:
            return False
    else:
        return True

n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))

for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)

Submission status: Runtime Error

Solution code:
N=int(input())
robbot=[input().split() for i in range(N)]
roba=[x[0] for x in robbot]
robb=[x[1] for x in robbot]
robc=list(map(int,roba))
robd=list(map(int,robb))
tas1=[x+y for (x,y) in zip (robc,robd)]
tas2=[x-y for (x,y) in zip (robc,robd)]
del tas2[0]
del tas1[-1]
tas3=[x-y for (x,y) in zip (tas2,tas1)]
tas4=[i for i in tas3 if i>=0 or i-1>=0]
print(len(tas5))

Submission status: Runtime Error

Solution code:
from operator import itemgetter

N = int(input())
input_list = []
lobot_list = []
tmp_lobot_list = []
for i in range(N):
    tmp = input()
    tmp_list = tmp.split()
    tmp_lobot_list.append(tmp_list)
    
sorted(tmp_lobot_list,key=itemgetter(0))



for i in range(N):
    tmp = tmp_lobot_list[i]
    a = tmp[0]
    b = tmp[1]

    lobot_list.append(a-b)
    lobot_list.append(a+b)


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

Submission status: Runtime Error

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: Runtime Error

Solution code:
list=[]
i=0
j=0
r=0
n=int(input())

while i<n:
  i+=1
  a, b = map(int, input().split())
  list.append([a,b])

list.sort()

if(4<=n):
  while j<n-2:
    if(list[j][0]+listl[j][1] > list[j+1][0]-listl[j+1][1]):
      r+=1
      if(list[j+1][0]+list[j+1][1] > list[j+2][0]-list[j+2][1]):
        r-=1
    j+=1

  if(list[n-2][0]+list[n-2][1] > list[n-1][0]-list[n-1][1]):
    r+=1
    if(list[n-1][0]+list[n-1[1]] > list[n][0]-list[n][1]):
      r-=1
    if(list[n-2][0]+list[n-2[1]] > list[n][0]-list[n][1]):
      r+=1
else:
  if(list[0][0]+list[0][1] > list[1][0]-list[1][1]):
    r+=1
    if(list[1][0]+list[1][1] > list[2][0]-list[2][1]):
      r-=1
    if(list[0][0]+list[0][1] > list[2][0]-list[2][1]):
      r+=1
  if(list[1][0]+list[1][1] > list[2][0]-list[2][1]):
    r+=1
print(n-r)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [0]*N
t = [0]*N
for i in range(N):
    s[i],t[i] = input().split()
s = [int(x) for x in s]
t = [int(x) for x in t]
def sel(a,b):
    u = []
    c = 0
    for i in range(len(a)-1):
        if abs(a[i+1] - a[i]) < b[i+1] + b[i]:
            c = c + 1
            a.pop(i)
            b.pop(i)
            a1 = a
            b1 = b
            sel(a1,b1)
            c = 0
    if c == 0:
        u.append(len(a))
    return u
u1 = sorted(sel(s,t))
print(u1[-1])

Submission status: Runtime Error

Solution code:
N=int(input())
XL=[]
for i in range(N):
  T=list(map(int,input().split()))
  XL.append(T)
M=[[] for z in range(N)] #M[i]はiと可動範囲がかぶっているロボットの集合
for i in range(N-1):
  for j in range(i+1,N):
    if XL[j][0]-XL[j][1]<XL[i][0]+XL[i][1] and XL[i][0]-XL[i][1]<XL[j][0]+XL[j][1]:
      M[i].append(j)
      M[j].append(i)
c=0
t=N
while M != [[] for z in range(t)]:
  Len=[0 for z in range(t)]
  q=0
  p=0
  for i in range(t):
    Len[i]=len(M[i])
    if Len[i]>q:
      q=Len[i]
      p=i
  M.pop(M[p])
  t=t-1
  for i in range(t):
    if (p in M[i]) == True:
      M[i].remove(p)
  c=c+1
print(N-c)

Submission status: Runtime Error

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: Runtime Error

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]
                    i -= 1
                    seq = 0
                else:
                    xls.append(xl)
                    seq = 0       
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input().strip())
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
list_N = list(range(1,N+1))
grid.sort()
a = 0
count = 0
while a < N :
  list_a = list(range(grid[a][0]-grid[a][1]+1, grid[a][0]+grid[a][1]-1))
  list_b = list(set(list_a) - set(list_N))
  if list_b == []:
    list_N = list(set(list_N) - set(list_a))
    count += 0
  else:
    count += 1
print(count)

Submission status: Runtime Error

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