https://www.acmicpc.net/problem/14501
n = int(input())
t = []
p = []
dp = [0] * (n+1)
max_value = 0
for _ in range(n):
x, y = map(int, input().split())
t.append(x)
p.append(y)
for i in range(n-1, -1, -1):
time = t[i] + i
if time <= n:
dp[i] = max(p[i] + dp[time], max_value)
max_value = dp[i]
else:
dp[i] = max_value
print(max_value)
https://www.acmicpc.net/problem/18353
n = int(input())
array = list(map(int, input().split()))
array.reverse()
dp = [1] * n
for i in range(1, n):
for j in range(0, i):
if array[j] < array[i]:
dp[i] = max(dp[i], dp[j] + 1)
print(n-max(dp))
def maxGold(arr, x, y):
for j in range(1, y):
for i in range(x):
if i == 0:
left_top = 0
else:
left_top = arr[i-1][j-1]
if i == x-1:
left_btm = 0
else:
left_btm = arr[i+1][j-1]
left = arr[i][j-1]
arr[i][j] = max(left_top, left, left_btm)+arr[i][j]
finals=[]
for i in range(x):
finals.append(arr[i][y-1])
return max(finals)
t = int(input())
for _ in range(t):
n,m = map(int, input().split())
arr=[]
temp = list(map(int, input().split()))
for i in range(0, len(temp), m):
arr.append(list(temp[i:i+m]))
print(maxGold(arr,n,m))