def max_path_sum(tri, m, n):
    if not tri or m == 0 or n == 0:
        return 0

    dp = tri[-1][:]

    for row in range(m - 2, -1, -1):
        for col in range(row + 1):
            dp[col] = tri[row][col] + max(dp[col], dp[col + 1])

    return dp[0]