atcoder#ABC210D. [ABC210D] National Railway
[ABC210D] National Railway
Score : points
Problem Statement
The Kingdom of Takahashi can be represented as a grid with rows and columns. Let denote the square at the -th row from the north and -th column from the west.
Recently, there have been more and more requests from the kingdom's citizens to build a railway, and now the king, Takahashi, has no choice but to build one. The construction of the railway will have the following two phases.
- First, choose two different squares and build a station on each of them. It costs yen to build a station on the square .
- Then, build a railway track connecting these two stations. This costs yen when the two stations are on the squares and . ( denotes the absolute value of .)
Takahashi's priority is to spend as little as possible on this construction, rather than to improve convenience for the citizens. Print the minimum possible total cost of the construction of the railway.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible total cost of the construction of the railway.
3 4 2
1 7 7 9
9 6 3 7
7 8 6 4
10
If we build stations on the squares and , it will cost yen to build the stations and yen to build the track, for a total of yen. This is the minimum possible total cost of the construction.
3 3 1000000000
1000000 1000000 1
1000000 1000000 1000000
1 1000000 1000000
1001000001