-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaac1p6.py
49 lines (43 loc) · 956 Bytes
/
aac1p6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import sys
from bisect import bisect_left
input = sys.stdin.readline
def update(ind, v):
while ind <= 4000000:
BIT[ind] = max(BIT[ind], v)
ind += ind & (-ind)
def query(ind):
m = 0
while ind >= 1:
m = max(m, BIT[ind])
ind -= ind & (-ind)
return m
n = int(input())
BIT = [0] * 4000001
tmp = []
v = set()
for _ in range(n):
a, b = [int(x) for x in input().split()]
tmp.append([a, b, a - b, a + b])
v.add(a)
v.add(b)
v.add(a - b)
v.add(a + b)
v = sorted(list(v))
m = {}
for i in range(len(v)):
m[v[i]] = i + 1
tmp.sort()
alpacas = [[m[x] for x in tmp[i]] for i in range(n)]
dp = [1] * n
ins = [[] for _ in range(n + 1)]
for i in range(n):
a, b, c, d = alpacas[i]
for x, y in ins[i]:
update(x, y)
dp[i] = query(c) + 1
ind = bisect_left(alpacas, [d, -1, 0, 0])
ins[ind].append([a, dp[i]])
# print(alpacas)
# print(dp)
# print(BIT[:30])
print(max(dp))