#DSU0000014. Những hồ nước (The Lakes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những hồ nước (The Lakes)
The Lakes
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A region is represented by a grid of rows and columns. The integer gives the water depth at cell . Cells of depth are land. Positive-depth cells belong to the same lake if they can be connected through other positive-depth cells by moving up, down, left, or right.
The volume of a lake is the sum of depths of its cells. Find the maximum lake volume.
Input
The first line contains two integers . Each of the next lines contains integers giving the depths .
Output
Print the volume of the largest lake, or 0 if the grid contains no lake.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
3 3
1 2 0
3 4 0
0 0 5
Output
10
Explanation
The four positive cells at the top left form a lake of volume . The cell of depth forms another lake, so the answer is .