#K77532. Maximum Stars Collection
Maximum Stars Collection
Maximum Stars Collection
You are given an n × m grid where each cell contains a non-negative integer representing the number of stars. A robot starts at the top-left corner (cell \(0, 0\)) and wants to reach the bottom-right corner (cell \(n-1, m-1\)). The robot can only move either right or down at each step. Your task is to determine the maximum number of stars the robot can collect along its path.
The robot collects the stars in each visited cell. Formally, if the path covers exactly \(n+m-1\) cells, the total stars collected is the sum of the stars in these cells.
inputFormat
The first line contains two integers n
and m
(1 ≤ n, m ≤ 103), representing the number of rows and columns of the grid respectively.
Each of the following n
lines contains m
space-separated integers, where the j-th integer in the i-th line represents the number of stars in cell \((i-1, j-1)\).
outputFormat
Output a single integer: the maximum number of stars that can be collected when traveling from the top-left corner to the bottom-right corner of the grid under the movement restrictions.
## sample3 3
1 3 1
1 5 1
4 2 1
12