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
x,y = map(int,input().split())
c = [[0]*(y+1)] + [[0] + list(map(int, input().split())) for i in range(x)]
for i in range(1,x+1):
for j in range(1,y+1):
c[i][j] = max(c[i-1][j],c[i][j-1]) + c[i][j]
ans = ''; i, j = x, y
while i > 0 and j > 0 :
if i == 1 and j == 1: break
if (c[i-1][j] > c[i][j-1] and i - 1 != 0 ) or (c[i][j-1] == 0 and j-1 == 0): ans = "D" + ans; i -= 1
else: ans = "R" + ans; j -= 1
print(c[-1][-1])
if ans != '': print(*ans)