Submission #1187992

#TimeUsernameProblemLanguageResultExecution timeMemory
1187992ofozBouquet (EGOI24_bouquet)Pypy 3
0 / 100
3099 ms62596 KiB
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(max(i-l-1, i-10), -1, -1):
            if j < 0: break

            l2, r2 = segments[j]
            if j + r2 < i:
                dp[i] = max(dp[i], dp[j] + 1)
                
    # print(dp)
    print(max(dp))

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

Compilation message (stdout)

Compiling 'Main.py'...

=======
  adding: __main__.pyc (deflated 30%)

=======
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...