Here is my code
import sys
def myInput1():
line = ''
while line == '':
line = sys.stdin.readline().strip()
return line
def myInput(txt):
#return myInput1(), []
npos = -1
for i in xrange(len(txt)):
if txt[i] == '\n':
npos = i
break
if npos == -1:
return ''.join(txt), []
line = ''.join(txt[:npos])
txt = txt[npos+1:]
return line, txt
def Solve_Case(n,m,floor):
for i in xrange(1,n):
for j in xrange(1,m+1):
floor[i][j] += max(floor[i-1][j-1:j+2])
return max(floor[n-1])
txt = ['1',
'6 5',
'3 1 7 4 2',
'2 1 3 1 1',
'1 2 2 1 8',
'2 2 1 5 3',
'2 1 4 4 4',
'5 2 7 5 1']
txt = list('\n'.join(txt))
floor = []
for _ in xrange(100):
floor.append([0]*102)
line, txt = myInput(txt)
t = int(line)
for ttt in xrange(t):
line, txt = myInput(txt)
(n,m) = line.split()
(n,m) = (int(n), int(m))
for i in xrange(n):
line, txt = myInput(txt)
snums = [s for s in line.split() if s!='']
for j in xrange(m):
floor[i][1+j] = int(snums[j])
res = Solve_Case(n,m,floor)
print str(res)
`
I get WA with this code which means it works. This code imitates input. If I uncomment line in function myInput() I get NZEC. When uncommenting code reads from stdin skiping blank lines. Also in lines like '1 2 3 4' code will skip ' ' and normally form array [1, 2, 3, 4].
About correctness. I tested for any possible little cases and for 1 big case 100 x 100 and it works fine.