#P7640. [BalticOI 2006] CITY PLANNING (Day 2)
[BalticOI 2006] CITY PLANNING (Day 2)
Description
A space station will be built on a planet. The station will employ people. They must live somewhere, so a city will be built around the station. The land around the station is divided into equal-sized square blocks, and on each block it is possible to build an apartment building with at most floors. Each building must contain exactly one apartment on each floor, and each person must live in a separate apartment.
The space station is located at coordinates . The other blocks are numbered as shown below:

Because traffic between blocks can only move along streets, the distance from block to the space station is units.
The cost of building a building equals the sum of the costs of building its floors. As is well known, the cost of building a floor depends only on the floor height, not on the building location.
The buildings will be used for years. The people living in these buildings will commute to the space station for work. Over these years, transporting one person to and from the station will cost , where is the distance from the person’s building to the space station.
We may assume that the planet is large enough and the city occupies only a small part of its surface, so we do not need to consider the curvature of the planet.
Your task is to write a program to determine the minimum total cost over years for building the housing and operating the transportation system.
Input Format
The first line contains integers , , and . The next lines specify the construction cost per apartment for each floor. Line contains an integer , meaning the cost to build one apartment on the -th floor (assuming all floors below the -th have already been built).
It is well known that building a higher floor is always more expensive than building a lower floor: .
Output Format
The only line contains one integer: the total cost of building the city and operating the transportation system for years.
17 5 4
100
107
114
121
1778
Hint
Constraints
For of the testdata, , , , . It is guaranteed that the answer does not exceed (that is, it fits in a 64-bit signed integer).
Notes
From Baltic Olympiad in Informatics 2006 Day 2:City.
Translated and organized by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号