QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17971. Smart Warehouse

統計

Hyundai AutoEver is a company leading the future of mobility innovation, transforming the paradigm of smart logistics in the Fourth Industrial Revolution.

Hyundai AutoEver is testing a smart warehouse in which items are placed in the form of an $N \times M$ grid. Let's denote the cell in the $r$-th row from the top and the $c$-th column from the left as $(r, c)$. Each cell $(r, c)$ has an item whose value is $A_{rc}$. The value of an item can be negative.

A robot in the warehouse is sometimes instructed to transport an item outside. For efficient transportation, the robot can also transport nearby items together as a rectangular group. Specifically, suppose the robot is instructed to transport an item at cell $(r, c)$. In that case, the robot selects four integers $r_1$, $r_2$, $c_1$, $c_2$ such that $1 \le r_1 \le r \le r_2 \le N$, $1 \le c_1 \le c \le c_2 \le M$, and then transports all items inside the rectangular area $[r_1, r_2] \times [c_1, c_2]$.

For each of the $NM$ items, calculate the maximum sum of values of the items that can be transported when the robot is instructed to transport the item.

Input

The first line of input contains two space-separated integers $N$ and $M$, denoting the size of the warehouse. ($2 \le N \le 500$; $2 \le M \le 500$)

The $r$-th of the following $N$ lines contains $M$ space-separated integers $A_{r1}$, $A_{r2}$, $\cdots$, $A_{rM}$, which correspond to the value of each item in the $r$-th row of the grid. ($-10^3 \le A_{rc} \le 10^3$)

Output

Print $N$ lines in total. In the $r$-th line of output, print $M$ integers, which denote the maximum sum of values of the items that can be transported when the robot is instructed to transport the item at each of the cells $(r, 1)$, $(r, 2)$, $\cdots$, $(r, M)$.

Examples

Input 1

3 4
2 2 2 2
2 -8 0 -12
2 -8 7 5

Output 1

8 8 9 8 
6 1 9 4 
6 6 12 12

Input 2

2 2
-1 -3
2 -1

Output 2

1 -3 
2 1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.