#C10876. Maximum Gold Collection

    ID: 40129 Type: Default 1000ms 256MiB

Maximum Gold Collection

Maximum Gold Collection

You are given a grid of size (n \times m) where each cell contains a certain number of gold coins. Starting from the top-left cell, your task is to determine the maximum number of gold coins you can collect by moving only to the right or down until you reach the bottom-right cell.

Formally, let (G[i][j]) represent the gold coins in cell ((i,j)). You need to maximize the sum along a path from (G[1][1]) to (G[n][m]) given that from any cell you can only move to the cell directly to the right or directly below.

inputFormat

The input is provided via standard input (stdin). The first line contains two integers (n) and (m), denoting the number of rows and columns respectively. This is followed by (n) lines, each containing (m) integers representing the grid, where each integer denotes the number of gold coins in that cell.

outputFormat

Output a single integer to standard output (stdout) — the maximum number of gold coins that can be collected from the top-left to the bottom-right cell.## sample

3 3
1 3 1
1 5 1
4 2 1
12