Input The input is given from standard input in the following format. $H \ W$ $a{1, 1} \…
- User
Input
The input is given from standard input in the following format.
Assistant
pythondef main(): import sys input = sys.stdin.read().split() idx = 0 H = int(input[idx]) idx += 1 W = int(input[idx]) idx += 1 grid = [] for _ in range(H): row = list(map(int, input[idx:idx+W])) idx += W grid.append(row) dp = [[0]*W for _ in range(H)] dp[0][0] = grid[0][0] for j in range(1, W): dp[0][j] = dp[0][j-1] + grid[0][j] for i in range(1, H): dp[i][0] = dp[i-1][0] + grid[i][0] for i in range(1, H): for j in range(1, W): dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + grid[i][j] print(dp[H-1][W-1]) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.