One morning, fruit farmer Fred visits his apple trees and notices that one of them was cut overnight. This means a loss of 111e . the money he can make from the apples of a tree on average. In order to prevent further losses, he decides to erect a fence on his plantation. The fence consists of posts connected by wire. The fence posts can only be placed at a given set of pre-drilled holes. While Fred can get wire for free, he needs to buy the fence posts for 20e each. So it might not always be worth or even possible to fence in all of his trees. The plantation is square and 1 000×1 000 m2 large. In bird’s eye view, the lower left corner has coordinates (0, 0), the upper right (1 000, 1 000).
In this example there are four pre-drilled holes (circles) and three trees (squares). It is optimal to buy three fence posts and put them into selected holes (filled circles), to connect them by wire (lines), and to leave the upper left hole empty. The cost of erecting the fence is 3 x 20 + 1 x 111 = 171 since three posts were bought and one tree could not be fenced in (which means a loss of that tree’s harvest). Write a program that reads the positions of the pre-drilled holes and the trees on Fred’s plantation and outputs the minimum cost of erecting a fence or erecting no fence at all. You can neglect the actual shape of the trees and calculate with their positions only.
입력 4 3 800 300 200 200 200 700 600 700 400 300 600 500 800 900 출력 171
출처:ceoi/2008/