map int input split list map int input split for in range for in range

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
n, m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [[0]*m for i in range(n)]
b[0][0] = a[0][0]
for i in range(1, m): b[0][i] = b[0][i-1] + a[0][i]
for j in range(1, n): b[j][0] = b[j-1][0] + a[j][0]
for i in range(1, n):
for j in range(1, m):
b[i][j] = max(b[i][j-1],b[i-1][j]) + a[i][j]
print(b[n-1][m-1])
for i in range(len(b)):
print(*b[i])
s = ''; i, j = n-1, m-1
while i != 0 or j != 0:
if i > 0 and b[i][j]-a[i][j] == b[i-1][j]:
s = 'D'+s
i -= 1
else:
s = 'R'+s
j -= 1
print(s)