Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Building A New Barn
Description After scrimping and saving for years, Farmer John has decided to build a new barn. He wants the barn to be highly accessible, and he knows the coordinates of the grazing spots of all Y) (-10,000 ≤ _{i}X ≤ 10,000; -10,000 ≤ _{i}Y ≤ 10,000). The hungry cows never graze in spots that are horizontally or vertically adjacent._{i}The barn must be placed at integer coordinates and cannot be on any cow's grazing spot. The inconvenience of the barn for any cow is given the Manhattan distance formula | Y - Y|, where (_{i}X, Y) and (X, _{i}Y) are the coordinates of the barn and the cow's grazing spot, respectively. Where should the barn be constructed in order to minimize the sum of its inconvenience for all the cows?_{i}Input Line 1: A single integer: N
Lines 2.. N+1: Line i+1 contains two space-separated integers which are the grazing location (X, _{i}Y) of cow _{i}iOutput Line 1: Two space-separated integers: the minimum inconvenience for the barn and the number of spots on which Farmer John can build the barn to achieve this minimum. Sample Input 4 1 -3 0 1 -2 1 1 -1 Sample Output 10 4 Hint The minimum inconvenience is 10, and there are 4 spots that Farmer John can build the farm to achieve this: (0, -1), (0, 0), (1, 0), and (1, 1). Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator