P4955 [USACO14JAN] Cross Country Skiing S

Description

The cross-country skiing course at the winter Moolympics is described by an $M * N$ grid of elevations (1

Input Format

* Line 1: The integers $M$ and $N$. * Lines 2..1+M: Each of these $M$ lines contains $N$ integer elevations. * Lines 2+M..1+2M: Each of these $M$ lines contains $N$ values that are either $0$ or $1$, with $1$ indicating a cell that is a waypoint.

Output Format

The ski course is described by a 3 x 5 grid of elevations. The upper-left, upper-right, and lower-right cells are designated as waypoints.

Explanation/Hint

If D = 21, the three waypoints are reachable from each-other. If D < 21, then the upper-right waypoint cannot be reached from the other two.