eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Honeymoon Hike

Honeymoon Hike

Emma is on a hiking trip with Eric, her freshly-married husband, for their honeymoon. They are hiking from one cabin to the next every day. Unfortunately, Eric is not as fit as Emma and is slowly getting tired. Since Emma does not want to start their newly-formed marriage with a serious conflict (and needs somebody to keep her warm in the nights), she decides to plan the next day trips so that they are not so strenuous for Eric. In the past days, Emma has discovered a surprising fact about her husband. He is not so much tired by the length of their daily trip or the total amount of meters they had to climb. Instead, Eric is tired the more, the bigger the difference between the highest and the lowest point of today's route becomes. Emma assumes this is due to psychological factors. It just sounds a lot more difficult to climb once from \textbf{500} meter to \textbf{1500} meters than to climb from \textbf{200} to \textbf{400} meters ten times, although you climbed twice as much in the latter case. Given an altitude map of the terrain, you should help Emma in finding a path that minimizes the difference between its highest and its lowest elevation, so that Eric does not feel as tired. The cabin they start at is located at the top-left corner and their destination is the bottom-right corner of the map. They can move along any of the four major directions but not on a diagonal. \InputFile The first line contains the number of scenarios. Each scenario starts with a number \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{100}), the size of the area. The elevations of the terrain are given as a \textbf{n×n} integer matrix (\textbf{h_i}_\{,j\}) (\textbf{0} ≤ \textbf{h_i}_\{,j\} ≤ \textbf{200}) on \textbf{n} lines, where each line contains \textbf{n} space-separated elevations. \OutputFile The output for every scenario begins with a line containing "\textbf{Scenario #i:}", where \textbf{i} is the number of the scenario starting at \textbf{1}. Then, print a single line containing the difference between the highest and the lowest elevation on the optimal path. Terminate the output for the scenario with a blank line.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
1
5
1 1 3 6 8
1 2 2 5 5
4 4 0 3 3
8 0 2 2 4
4 3 0 3 1
Вихідні дані #1
Scenario #1:
3