from sys import setrecursionlimit, stdout
from math import ceil, floor
def solve():
n = int(input())
segments = []
for _ in range(n):
l, r = map(int, input().split(" "))
segments.append((l, r))
dp = [0] * n
for i in range(n):
l, r = segments[i]
dp[i] = 1
for j in range(0, i-l):
l2, r2 = segments[j]
if j + r2 < i:
# print(i, j)
dp[i] = max(dp[i], dp[j] + 1)
print(dp[-1])
# let dp[i] be the maximum amount of tulips we can pick up in the i-th point, if we have boundaries l, r. then we can see that dp[i] = max(dp[i-1], dp[j] + 1)
# for some j < i such that i-j >= l and i-j >= r_j
# so now we just need to find the first tulip j in point 0, i-l such that
solve()
컴파일 시 표준 출력 (stdout) 메시지
Compiling 'Main.py'...
=======
adding: __main__.pyc (deflated 30%)
=======
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |