Buggy python submission (verdict: Time Limit Exceeded):
import sys

input=sys.stdin.readline

R,C,K=map(int,input().split())
item={}
for i in range(K):
    r,c,v=map(int,input().split())
    item[r-1,c-1]=0
    item[r-1,c-1]=v

dp=[[0 for i in range(3)] for j in range(C)]

if (R-1,C-1) in item:
    dp[C-1][0]=item[R-1,C-1]
    dp[C-1][1]=item[R-1,C-1]
    dp[C-1][2]=item[R-1,C-1]

for j in range(C-2,-1,-1):
    if (R-1,j) in item:
        dp[j][0]=max(dp[j+1][1]+item[R-1,j],dp[j+1][0])
        dp[j][1]=max(dp[j+1][2]+item[R-1,j],dp[j+1][1])
        dp[j][2]=max(item[R-1,j],dp[j+1][2])
    else:
        dp[j][0]=dp[j+1][0]
        dp[j][1]=dp[j+1][1]
        dp[j][2]=dp[j+1][2]

for i in range(R-2,-1,-1):
    ndp=[[0 for i in range(3)] for j in range(C)]
    if (i,C-1) in item:
        ndp[C-1][0]=dp[C-1][0]+item[i,C-1]
        ndp[C-1][1]=dp[C-1][0]+item[i,C-1]
        ndp[C-1][2]=dp[C-1][0]+item[i,C-1]
    else:
        ndp[C-1][0]=dp[C-1][0]
        ndp[C-1][1]=dp[C-1][0]
        ndp[C-1][2]=dp[C-1][0]
    for j in range(C-2,-1,-1):
        if (i,j) in item:
            ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i,j],ndp[j+1][0])
            ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i,j],ndp[j+1][1])
            ndp[j][2]=max(dp[j][0]+item[i,j],ndp[j+1][2])
        else:
            ndp[j][0]=max(dp[j][0],ndp[j+1][0])
            ndp[j][1]=max(dp[j][0],ndp[j+1][1])
            ndp[j][2]=max(dp[j][0],ndp[j+1][2])
    dp=ndp

print(dp[0][0])


Fixed submission:
import sys

input=sys.stdin.readline

R,C,K=map(int,input().split())
item=[[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r,c,v=map(int,input().split())
    item[r-1][c-1]=v

dp=[[0 for i in range(3)] for j in range(C)]
dp[C-1][0]=item[R-1][C-1]
dp[C-1][1]=item[R-1][C-1]
dp[C-1][2]=item[R-1][C-1]

for j in range(C-2,-1,-1):
    dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0])
    dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1])
    dp[j][2]=max(item[R-1][j],dp[j+1][2])


for i in range(R-2,-1,-1):
    ndp=[[0 for i in range(3)] for j in range(C)]
    ndp[C-1][0]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][1]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][2]=dp[C-1][0]+item[i][C-1]
    for j in range(C-2,-1,-1):
        ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0])
        ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1])
        ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2])
    dp=ndp

print(dp[0][0])

Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
item={}
for i in range(K):
    r,c,v=map(int,input().split())
    item[r-1,c-1]=0
    item[r-1,c-1]=v

dp=[[[0 for k in range(3)] for j in range(C)] for i in range(R)]

if (R-1,C-1) in item:
    dp[R-1][C-1][0]=item[R-1,C-1]
    dp[R-1][C-1][1]=item[R-1,C-1]
    dp[R-1][C-1][2]=item[R-1,C-1]

for j in range(C-2,-1,-1):
    if (R-1,j) in item:
        dp[R-1][j][0]=max(dp[R-1][j+1][1]+item[R-1,j],dp[R-1][j+1][0])
        dp[R-1][j][1]=max(dp[R-1][j+1][2]+item[R-1,j],dp[R-1][j+1][1])
        dp[R-1][j][2]=max(item[R-1,j],dp[R-1][j+1][2])
    else:
        dp[R-1][j][0]=dp[R-1][j+1][0]
        dp[R-1][j][1]=dp[R-1][j+1][1]
        dp[R-1][j][2]=dp[R-1][j+1][2]

for i in range(R-2,-1,-1):
    if (i,C-1) in item:
        dp[i][C-1][0]=dp[i+1][C-1][0]+item[i,C-1]
        dp[i][C-1][1]=dp[i+1][C-1][0]+item[i,C-1]
        dp[i][C-1][2]=dp[i+1][C-1][0]+item[i,C-1]
    else:
        dp[i][C-1][0]=dp[i+1][C-1][0]
        dp[i][C-1][1]=dp[i+1][C-1][0]
        dp[i][C-1][2]=dp[i+1][C-1][0]

for i in range(R-2,-1,-1):
    for j in range(C-2,-1,-1):
        if (i,j) in item:
            dp[i][j][0]=max(max(dp[i+1][j][0],dp[i][j+1][1])+item[i,j],dp[i][j+1][0])
            dp[i][j][1]=max(max(dp[i+1][j][0],dp[i][j+1][2])+item[i,j],dp[i][j+1][1])
            dp[i][j][2]=max(dp[i+1][j][0]+item[i,j],dp[i][j+1][2])
        else:
            dp[i][j][0]=max(dp[i+1][j][0],dp[i][j+1][0])
            dp[i][j][1]=max(dp[i+1][j][0],dp[i][j+1][1])
            dp[i][j][2]=max(dp[i+1][j][0],dp[i][j+1][2])

print(dp[0][0][0])


Fixed submission:
import sys

input=sys.stdin.readline

R,C,K=map(int,input().split())
item=[[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r,c,v=map(int,input().split())
    item[r-1][c-1]=v

dp=[[0 for i in range(3)] for j in range(C)]
dp[C-1][0]=item[R-1][C-1]
dp[C-1][1]=item[R-1][C-1]
dp[C-1][2]=item[R-1][C-1]

for j in range(C-2,-1,-1):
    dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0])
    dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1])
    dp[j][2]=max(item[R-1][j],dp[j+1][2])


for i in range(R-2,-1,-1):
    ndp=[[0 for i in range(3)] for j in range(C)]
    ndp[C-1][0]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][1]=dp[C-1][0]+item[i][C-1]
    ndp[C-1][2]=dp[C-1][0]+item[i][C-1]
    for j in range(C-2,-1,-1):
        ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0])
        ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1])
        ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2])
    dp=ndp

print(dp[0][0])