[アルゴリズム]伯準-14501(退社)/派森

4548 ワード

import sys
N = int(sys.stdin.readline())
answer = [0] * (N+2)
array = [[0,0]]

for i in range(N):
    array.append(list(map(int,sys.stdin.readline().split())))

array.append([0,0])
maxValue = 0
for i in range(N+1 , 0 , -1):
    t = array[i][0]
    p = array[i][1]
    if(i + t  <= N+1):
        maxValue = max(answer[i + t] + p, maxValue)
    answer[i] = maxValue


print(maxValue)