QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 64 MB Puntuación total: 100

#16439. Skiing

Estadísticas

Michael likes skiing. This is not surprising, as skiing is indeed exciting. However, to gain speed, the ski area must slope downwards, and once you reach the bottom of the slope, you have to take a lift back up or wait for the lift to pick you up. Michael wants to know the longest ski path in a given area. The area is given as a 2D array, where each number in the array represents the altitude of that point.

Here is an example:

 1  2  3  4  5
16 17 18 19  6
15 24 25 20  7
14 23 22 21  8
13 12 11 10  9

A person can slide from a point to one of the four adjacent points (up, down, left, right) if and only if the altitude decreases. In the example above, a possible ski path is $24-17-16-1$ (starting at $24$ and ending at $1$). Of course, $25-24-23-\dots-3-2-1$ is longer. In fact, it is the longest one.

Input

The first line of the input contains the number of rows $R$ and columns $C$ of the 2D array ($1 \le R, C \le 100$). The following $R$ lines each contain $C$ numbers, representing the altitudes.

Output

Output the length of the longest ski path in the area.

Examples

Input 1

5 5
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

Output 1

25

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.