pastebin

Paste Search Dynamic
Recent pastes
db
  1. n = int(input())
  2. arr = []
  3. dp = [0]
  4. for _ in range(n):
  5.     a, b = map(int, input().split())
  6.     arr.append([a, b])
  7.     dp.append(b)
  8. print(dp)
  9. for i in range(n-1,-1,-1):
  10.     d, c = arr[i]
  11.     if i + d > n:
  12.         dp[i] = dp[i+1]
  13.     else:
  14.         dp[i] = max(dp[i+d], dp[i] + c)
  15.     print(i, dp)
  16. print(dp[0])
Parsed in 0.005 seconds